Create Components from solid bodies and place them in a new Assembly

Create Components from solid bodies and place them in a new Assembly

p_kompier
Participant Participant
689 Views
7 Replies
Message 1 of 8

Create Components from solid bodies and place them in a new Assembly

p_kompier
Participant
Participant

I use multi bodies parts for all my modeling. My workflow is to make components and place them in a new assembly file located in the same folder. How can I write an iLogic rule that does just that?

0 Likes
Accepted solutions (1)
690 Views
7 Replies
Replies (7)
Message 2 of 8

WCrihfield
Mentor
Mentor

Hi @p_kompier.  That sounds like what the 'Make Components' tool does.  Have you been using that tool?

WCrihfield_0-1721397598208.png

Help link below:

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-0BFE6FE8-961C-43A1-A533-B9E02F781826 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 8

p_kompier
Participant
Participant

Dear Wesley,

 

That is exactly what I and the members of my team have been doing for the past few years, but I prefer to have it automated as I'd like for the rule to automatically adjust the part name (including a prefix of the project ID) and have it saved in the right folder (something that somehow regularly goes wrong). This rule would be safe and fool-proof solution to all multi-bodied-part > assembly transitions.

 

I assume that the general approach should be to first create a new assembly document.

Then all solid bodies (not surface bodies) should turned into components and saved as new part files to be then placed into the new assembly document for each solid body.

and then ultimately the document should be saved

0 Likes
Message 4 of 8

A.Acheson
Mentor
Mentor

See vba sample here from ManufacturingDevBlog for make components workflow via API

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 8

p_kompier
Participant
Participant

Dear Wesley,

 

The rule you shared works beautifully, thank you very much. So far there is only one problem however and that is that one of the part in my testcase does not have the derived solid, it also occured to me that all the other parts have a small green arrow in the derived part part browser vbut this one does not. It should be added that this part is created using a mirror + "New Solid" instead of an Extrude or Face feature. Please find attached a screenshot of the derived part browser and the modded code.

NoDerivedSolidBody.png

And here is the Code:

 

' Folder to place the new assembly and parts
Dim path As String: path = ThisDoc.Path & "/"
 
' Use the docs first 9 characters as prefix for the new filenames
Dim prefix As String: prefix = Left(ThisDoc.FileName(False), 9)
  
Dim doc As PartDocument
doc = ThisApplication.ActiveDocument
 
' Create new assembly
Dim assy As AssemblyDocument
assy = ThisApplication.Documents.Add(kAssemblyDocumentObject)
 
Dim sBody As SurfaceBody
For Each sBody In doc.ComponentDefinition.SurfaceBodies
  ' Create a part for each surfacebody
  Dim prt As PartDocument
  prt = ThisApplication.Documents.Add(kPartDocumentObject)
  
  Dim dpcs As DerivedPartComponents
  dpcs = prt.ComponentDefinition.ReferenceComponents.DerivedPartComponents
  
  Dim dpd As DerivedPartUniformScaleDef
  dpd = dpcs.CreateUniformScaleDef(doc.FullDocumentName)
     
  ' Exclude the other solid bodies
  Dim dpe As DerivedPartEntity
  For Each dpe In dpd.Solids
    If Not dpe.ReferencedEntity Is sBody Then
      dpe.IncludeEntity = False
    End If
  Next
  
  For Each dpe In dpd.Sketches
  dpe.IncludeEntity = False
  Next
 
  Call dpcs.Add(dpd)
  
  ' Save using prefix and solid body's name
  Call prt.SaveAs(path + prefix + sBody.Name + ".ipt", False)
      
  ' Place an instance of it inside the assembly
  Dim mx As Matrix
  mx = ThisApplication.TransientGeometry.CreateMatrix()
  Call assy.ComponentDefinition.Occurrences.AddByComponentDefinition(prt.ComponentDefinition, mx)
  
  ' Close the part
  Call prt.Close
Next
 
' Save the assembly
Call assy.SaveAs(path + prefix + "001" + ".iam", False)
 
Many thanks so far, I hope this final mystery can be solved.
0 Likes
Message 6 of 8

Q_Visser
Contributor
Contributor
Accepted solution

Hey @p_kompier,

I believe the issue stems from the fact that not all your solid bodies are marked for export (the green arrow). To solve this, you just need to insert the line(s) marked in red in the following portion of your code (the comment is optional):

 

Dim sBody As SurfaceBody
For Each sBody In doc.ComponentDefinition.SurfaceBodies
 ' Ensure solid body is marked for export
  sBody.Exported = True
  ' Create a part for each surfacebody
  Dim prt As PartDocument
  prt = ThisApplication.Documents.Add(kPartDocumentObject)
 
Hope that helps!
Cheers,
Q Visser

Current Software:
Inventor Professional 2024.2 & Vault Professional 2024.2
Message 7 of 8

p_kompier
Participant
Participant

Dear Q_Visser,

That did it, Thank you so much. My mbp>assy rule now really seems complete and ready to be implemented.

Cheers

0 Likes
Message 8 of 8

Q_Visser
Contributor
Contributor
No worries! It's always nice to be able to simplify a process.
Cheers,
Q Visser

Current Software:
Inventor Professional 2024.2 & Vault Professional 2024.2
0 Likes