Some help to get a macro started please

Some help to get a macro started please

stevec781
Collaborator Collaborator
394 Views
2 Replies
Message 1 of 3

Some help to get a macro started please

stevec781
Collaborator
Collaborator

I am going to write a macro to place a flat pattern view of every sheet metal part in an assembly onto a drawing sheet (all in the same IDW)

 

I am thinking the logic should be

 

for each part in the active assembly

if part is sheet metal

then send flat pattern to drawing

set scale

move insert point x & y so they dont all end up on top of each other

end if

 

and later I will add the same type of code to place the front view of a non sheet metal part but have to make sure it excludes frames as well.

next part.

 

I think this should be quite simple.

 

Where I am unsure is I need it to drill down into sub assemblies.  What is the best way to handle examination of the sub assemblies?  The top level assembly has parts and sub assemblies so I guess it must test for that first and if part then create flat pattern, but if sub assem then check parts and other sub assem's again.

Thanks in advance

Steve

 

 

0 Likes
395 Views
2 Replies
Replies (2)
Message 2 of 3

MegaJerk
Collaborator
Collaborator

If someone doesn’t answer this for you, I can tell you that I’m sort of working on the same thing. If I ever find the time to properly finish, I will gladly share my findings. Though this is somewhat unrelated, this is the code I use (while inside of an Assembly file (Top Level)) to go through all of the sheet metal parts. 

 

 

Public Sub SheetmetalConverter()
Dim topDoc As Document
Set topDoc = ThisApplication.ActiveDocument

Dim doc As Document

For Each doc In topDoc.AllReferencedDocuments
Call ProcessDoc(doc, topDoc)
Next
End Sub

Sub ProcessDoc(docPD As Document, topDocPD As AssemblyDocument)

'To make sure it's not library or read only
If docPD.IsModifiable = True Then

   'to make sure that it's a part and not anything else
   If (docPD.DocumentType = kPartDocumentObject) Then
      
      'to make sure that it's of the Sheet Metal subtype, and not a solid model 
      If (docPD.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}")  Then
      
       'place it in the drawing?
      End If 
    End If 
End If 
End Sub

 

(Note : The above example, and other code in this post is all VBA, not iLogic)

Though that above code will only work if you run it while you’re in an assembly file, you may be able to modify it to query an assembly that is somehow associated with the drawing file.

The below code is how I’m currently getting a single flat pattern to get thrown onto the drawing sheet. It’s still in the elementary steps, so it’s just a hard coded path.

 

Option Explicit

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("D:\PATH\PART.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

 (I believe I obtained that flat pattern code from around the forums, so, props to the person that made it!) 

So if I don't find the time to make something automated and sexy, perhaps you can. Or at least, this might help you to get started working in a good direction.  



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

GitHub
0 Likes
Message 3 of 3

stevec781
Collaborator
Collaborator

Thanks!  I was thing VBA not ilogic so that's a big help to get me started.

Thanks again.

0 Likes