Friday 9 December 2016

Part Number on Flat Pattern

I’ve told you before I like helping out on Autodesk Answer Days and it’s good to keep an eye on that when it happens.




That’s when you get some of the best questions because a lot of people have done the research, know there is no solution available unless an Autodesk employee looks at the code and provide the insight or blends a quick bit of code for your problem.

As I am aware not all of you have the time for it I try and share the best, rare, exceptional that catches my attention

                Exactly this case for the question “How to get Part Number on Flat Pattern”.

                Seems we have covered this before and you are correct to think this but it was a bit different for we have showed how to do that from the drawing using a symbol note before the export; you can read it all again here.

                But this is different for what he wants is to have the part number on the flat pattern in the model and I am guessing that is because he wants to do emboss it, cut it out or just have it as a text on his flat pattern exports.

                You know you can export the flat pattern or just a face, right?

                Right click on Flat Pattern and choose Save Copy As with sat, dxf, dwg as output or right click on a face and choose Export Face As with dxf, dwg as output.

               
Flat Pattern Save Copy As..



Export Face As

                The solution is simple brilliant and Cai from Autodesk has provided the answer.  Create a sketch on flat pattern face with a text in it and the code bellow will change that text to Part Number. All you need to do is run the iLogic code and watch the magic taking place.
               
Dim oDoc As PartDocument
 oDoc = ThisApplication.ActiveDocument
 
Dim oDef As SheetMetalComponentDefinition
oDef = oDoc.ComponentDefinition
 
Dim oSK As Sketch
oSK = oDef.FlatPattern.Sketches(1)
 
osk.TextBoxes(1).Text=iProperties.Value("Project", "Part Number")

How good is that? Because I find it brilliant.        

         Of course the user needed some more; as it happens with this things and we jumped right back to help him out.

         What if there is no sketch on flat pattern? Can I prompt the user to create it?

         Cai replied:

If oDef.FlatPattern.Sketches.Count >0 Then
 oSK = oDef.FlatPattern.Sketches(1)
Else
 ' There is no sketch
End If


And I (late as usual) told him to use a try/catch; here is the complete code:


Dim oDoc As PartDocument
 oDoc = ThisApplication.ActiveDocument
 
Dim oDef As SheetMetalComponentDefinition
oDef = oDoc.ComponentDefinition
 
Dim oSK As Sketch
Try
    oSK = oDef.FlatPattern.Sketches(1)
    osk.TextBoxes(1).Text=iProperties.Value("Project", "Part Number")
Catch
    MessageBox.Show("Sketch not found" _
                    & vbLf & "Please crete a sketch first", "No sketch")
    
End Try


Later,
ADS photo credit: Panoramas Washington - National Gallery of Art - Calder - 8-11-2014 - 17h18 (license)

No comments:

Post a Comment