Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sheet Metal Flat Pattern view insert in IDW code

6 REPLIES 6
Reply
Message 1 of 7
rthapa
2599 Views, 6 Replies

Sheet Metal Flat Pattern view insert in IDW code

I am working on a new iLogic rule that will create and IDW with automate views of the folded model of the sheet metal part in front view, right view, top view and the flat pattern I have success with all views except the flat pattern view creation codes. Does anyoone have knowledge of what the code terminology is to add a flat pattern view through ilogic to an idw?

 

Also, if this is possible, I want to create  a bend table and a hole table using ilogic to automate these processes.

 

So far, I can create any view off the folded model but I do not know the code to create a flat pattern view.

 

Please help.

 

6 REPLIES 6
Message 2 of 7
MegaJerk
in reply to: rthapa

I don't remember where I found this code, but at one time I had the same question.

I hope that this helps!

 

Public Sub AddFlatPatternDrawingView()

    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument

    'Set a reference to the active sheet.
    Dim oSheet As Sheet
    Set oSheet = oDrawDoc.ActiveSheet

    ' Create a new NameValueMap object
    Dim oBaseViewOptions As NameValueMap
    Set oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap

    ' Set the options to use when creating the base view.
    Call oBaseViewOptions.Add("SheetMetalFoldedModel", False)

    ' Open the sheet metal document invisibly
    Dim oModel As Document
    Set oModel = ThisApplication.Documents.Open("C:\Some\Crazy\Path\To\Your\Part\Here.ipt", False)

    ' Create the placement point object.
    Dim oPoint As Point2d
    Set oPoint = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)

    ' Create a base view.
    Dim oBaseView As DrawingView
    Set oBaseView = oSheet.DrawingViews.AddBaseView(oModel, oPoint, 1, _
    kDefaultViewOrientation, kHiddenLineRemovedDrawingViewStyle, _
    , , oBaseViewOptions)

End Sub
    

 

 

 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 3 of 7
rthapa
in reply to: MegaJerk

 
Thank you for your code. However, I was not able to make it work in Inventor 2012 Ilogic. I cleaned it up and removed the "SET" statements that are no longer used but I keep getting an error:
"Error in rule: FLAT PATTERN VIEW CREATE IN IDW, in document: FLAT PATTERN VIEW CREATE IN IDW.iLogicVb

Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.DrawingDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D467-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
The codes I have currently that work and create the formed views of the sheet metal part is as follows:
'------------------------start of iLogic code ---------------------

Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum

Dim oDrawingDoc as DrawingDocument    
Dim oPartDoc as Document
Dim oSheet As sheet
Dim oTG As TransientGeometry
Dim oView1 as DrawingView
Dim oView2 as DrawingView
Dim oView3 as DrawingView
Dim oView4 as DrawingView

'GET SHEET METAL FLAT PATTERN EXTENTS LENGTH TO CALCULATE VIEW SCALES

                            'MessageBox.Show(iProperties.Value("Custom","FlatExtentsLength"), "Title")
                            'MessageBox.Show(iProperties.Value("Custom","FlatExtentsWidth"), "Title")

FLATPATTERNLENGTH = iProperties.Value("Custom","FlatExtentsLength")
FLATPATTERNWIDTH = iProperties.Value("Custom","FlatExtentsWidth")

'Calculate View Scale
If FLATPATTERNLENGTH >= FLATPATTERNWIDTH Then
ViewScale = 5/FLATPATTERNLENGTH
Else
ViewScale = 5/FLATPATTERNWIDTH
End If    


'Ask to create drawing?
dwgQuery=MsgBox("Would you like to Create a drawing for this MODEL?", vbYesNo,"Drawing Selection")
If dwgQuery = vbYes Then
    oPartDoc = ThisDoc.Document
    
    'Define IDW Template File Location
    oDrawingDoc = ThisApplication.documents.Add(kDrawingDocumentObject, "pathandfilename.IDW", True)
    oSheet = oDrawingDoc.Sheets.Item(1)
    
    'Define 2d view bottom left corner points for four views
    oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(25#, 15#)
    oPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(33#, 15#)
    oPoint3 = ThisApplication.TransientGeometry.CreatePoint2d(25#, 20#)
    oPoint4 = ThisApplication.TransientGeometry.CreatePoint2d(4#, 10#)
                oView1 = oSheet.DrawingViews.AddBaseView(oPartDoc,oPoint1, ViewScale,kFrontViewOrientation, _
                kHiddenLineRemovedDrawingViewStyle)', KTANGENTEDGESON)
                oView2 = oSheet.DrawingViews.AddBaseView(oPartDoc,oPoint2, _
ViewScale,kRightViewOrientation,kHiddenLineRemovedDrawingViewStyle)
                oView3 = oSheet.DrawingViews.AddBaseView(oPartDoc,oPoint3, _
ViewScale,kTopViewOrientation,kHiddenLineRemovedDrawingViewStyle)

'-----------------------Flat Pattern View Section-------------------------------------------------------------------------
'This is the code line which I wish to use to add the sheet metal flat patter default view:
      oView4 = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint4, _
ViewScale,kIsoTopRightViewOrientation,kHiddenLineRemovedDrawingViewStyle, kSheetMetalFlatPattern, _
Camera1)'"sheetmetalflatpattern")'oBaseViewOptions)
                     
End If

'--------------------end of iLogic code-------------------------
Perhaps you can try my code. Note that you must launch this rule from within a model sheet metal .IPT file only. It will not work if you to try launching with an IDW or a non sheet metal part IPT open.
Perhaps Autodesk can help out to define the proper access code to the Sheet Metal Flat Pattern View. Further, how to define to show Tangent Edges in a formed view.
Thank you for your efforts.
Raj

Message 4 of 7
MegaJerk
in reply to: rthapa

That code was for VBA and not ilogic. I will try to make some ilogic code for you tomorrow (or later today if I have time).



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 5 of 7
mbranderhorst
in reply to: rthapa

Did you ever get this to work? If so could you please post it as I would also like to get this to work.

Thanks in advance.

Message 6 of 7
philip1009
in reply to: mbranderhorst

I'm not sure if this will work for 2012, but this is the sample provided by 2019 Inventor:

 

SyntaxEditor Code Snippet

' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

'Set a reference to the active sheet.
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet

' Create a new NameValueMap object
Dim oBaseViewOptions As NameValueMap
oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap

' Set the options to use when creating the base view.
oBaseViewOptions.Add("SheetMetalFoldedModel", False)

' Open the sheet metal document invisibly
Dim oModel As Document
oModel = ThisApplication.Documents.Open("C:\temp\SheetMetal.ipt", False)

' Create the placement point object.
Dim oPoint As Point2d
oPoint = ThisApplication.TransientGeometry.CreatePoint2d(25, 25)

' Create a base view.
Dim oBaseView As DrawingView
oBaseView = oSheet.DrawingViews.AddBaseView(oModel, oPoint, 1, _
kDefaultViewOrientation, kHiddenLineRemovedDrawingViewStyle, , , oBaseViewOptions)

Basically at the end of the Add Base View command there's a section for adding additional options specific to sheet metal, weldments, iPart/iAssembly, Positional, and Presentation views.  As you see in the middle of the sample it creates a Name Value Map and adds the option of SheetMetalFolded=False, then that argument is used in the drawing view creation where False means Flat.

Message 7 of 7
Cody.Redding
in reply to: rthapa

 

 You just needed to create the NameValueMap and assign the correct variable.  You were very close.  

 

Note: Per the 2017 API guide, this will only place the flat view, if it already exists in the part.  If it does not exist, then it will place a folded view.  

 

Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum

Dim oDrawingDoc as DrawingDocument    
Dim oPartDoc as Document
Dim oSheet As sheet
Dim oTG As TransientGeometry
Dim oView1 as DrawingView
Dim oView2 as DrawingView
Dim oView3 as DrawingView
Dim oView4 as DrawingView

'GET SHEET METAL FLAT PATTERN EXTENTS LENGTH TO CALCULATE VIEW SCALES

                            'MessageBox.Show(iProperties.Value("Custom","FlatExtentsLength"), "Title")
                            'MessageBox.Show(iProperties.Value("Custom","FlatExtentsWidth"), "Title")

FLATPATTERNLENGTH = iProperties.Value("Custom","FlatExtentsLength")
FLATPATTERNWIDTH = iProperties.Value("Custom","FlatExtentsWidth")

'Calculate View Scale
If FLATPATTERNLENGTH >= FLATPATTERNWIDTH Then
ViewScale = 5/FLATPATTERNLENGTH
Else
ViewScale = 5/FLATPATTERNWIDTH
End If    


'Ask to create drawing?
dwgQuery=MsgBox("Would you like to Create a drawing for this MODEL?", vbYesNo,"Drawing Selection")
If dwgQuery = vbYes Then
    oPartDoc = ThisDoc.Document
    
    'Define IDW Template File Location
    oDrawingDoc = ThisApplication.documents.Add(kDrawingDocumentObject, "pathandfilename.IDW", True)
    oSheet = oDrawingDoc.Sheets.Item(1)
    
    'Define 2d view bottom left corner points for four views
    oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(25#, 15#)
    oPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(33#, 15#)
    oPoint3 = ThisApplication.TransientGeometry.CreatePoint2d(25#, 20#)
    oPoint4 = ThisApplication.TransientGeometry.CreatePoint2d(4#, 10#)
                oView1 = oSheet.DrawingViews.AddBaseView(oPartDoc,oPoint1, ViewScale,kFrontViewOrientation, _
                kHiddenLineRemovedDrawingViewStyle)', KTANGENTEDGESON)
                oView2 = oSheet.DrawingViews.AddBaseView(oPartDoc,oPoint2, _
ViewScale,kRightViewOrientation,kHiddenLineRemovedDrawingViewStyle)
                oView3 = oSheet.DrawingViews.AddBaseView(oPartDoc,oPoint3, _
ViewScale,kTopViewOrientation,kHiddenLineRemovedDrawingViewStyle)


' Create a new NameValueMap object
Dim oBaseViewOptions As NameValueMap
oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap

' Set the options to use when creating the base view.
oBaseViewOptions.Add("SheetMetalFoldedModel", False)

'-----------------------Flat Pattern View Section-------------------------------------------------------------------------
'This is the code line which I wish to use to add the sheet metal flat patter default view:
      oView4 = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint4, _
ViewScale,kIsoTopRightViewOrientation,kHiddenLineRemovedDrawingViewStyle, , ,oBaseViewOptions)

End If

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report