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: 

Deriving Solids from Multi-Solid Body iPart

23 REPLIES 23
SOLVED
Reply
Message 1 of 24
Anonymous
2248 Views, 23 Replies

Deriving Solids from Multi-Solid Body iPart

Hello all,

 

I would like to write an iLogic rule that does the following for a currently open part that has multiple solid bodies:

 

1.  Derive each solid body as its own part

2.  Save derived part with one of three suffixes in the same folder as original part

3.  (Ideal, but optional) Place derived part in a new assembly with same name as original part

4.  Repeat for all solid bodies in original part

 

So why do I not just use the 'Make Components' function?  The parts that I need this rule to run on (there are hundreds) are all iParts, and the Make Components function is not available for iParts with multiple solid bodies.

 

Any help would be appreciated.  I have done very minimal coding in the past, but my usual method of Frankensteining code together from posted examples has failed me.  Thanks in advance.

 

 

23 REPLIES 23
Message 2 of 24
bradeneuropeArthur
in reply to: Anonymous

isn't it easier to break the link to the factory part and save-as the name you like?

This is out of the box inventor and no coding required...

 

Regards,

Autodesk Software: Inventor Professional 2018 | Vault Professional 2018 | Autocad Mechanical 2018
Programming Skills: Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Dimension Component! | Partlist Export! | Derive I-properties! | Vault Prompts Via API! | Vault Handbook/Manual!
Drawing Toggle Sheets! | Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 3 of 24
Anonymous
in reply to: bradeneuropeArthur

Sure, that would be easier but I need to maintain the link to the master iPart file. I have already been doing this manually, but I have hundreds of iPart members with three solid bodies each that need to be derived, named, and saved and I want to automate the process at least somewhat.
Message 4 of 24
bradeneuropeArthur
in reply to: Anonymous

Than first save copy as and break the link then. Reverse direction!

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 5 of 24
Anonymous
in reply to: bradeneuropeArthur

Either I'm not understanding what you mean, or you're not understanding my needs. The final derived parts (and the assembly made from those parts) *needs* to have an unbroken link to the original master iPart factory.
Message 6 of 24
bradeneuropeArthur
in reply to: Anonymous

Please send me a pack and go of a simple I-assembly and I will show you how I assume things can be done easily.

Maybe we don't understand each other correct, but than we know.

Afterwards I will send you an example back...

 

Regards, 

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 7 of 24
Anonymous
in reply to: bradeneuropeArthur

Here is a sample part.  In essence what I need here is an iLogic rule that performs the same function as the 'Make Components' button, which is deactivated for iParts with multiple solid bodies.  The end result needs to be that every solid from every member needs to be its own file, in the same folder as the members, and an assembly with the same name as the members, and all of it with a live link back to the master iPart so I can make top level changes that propagate down to every file.

Message 8 of 24
bradeneuropeArthur
in reply to: Anonymous

What inventor version are you using.

multi body is supported in inventor 2018 with I parts!

 

now I understand what you mean.

Talking about different things.

Sorry

I will take a look for some code for this.

 

I will come back ASAP

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 9 of 24
Anonymous
in reply to: bradeneuropeArthur

I am using Inventor 2017 Professional.  When I make an iPart with multiple solid bodies the 'Make Components' button is greyed out like in the screenshot.  Are you saying that in 2018 this feature is available?  If so that's very frustrating since we won't be upgrading to 2018 for several months at my company.

Message 10 of 24
bradeneuropeArthur
in reply to: Anonymous

Modified my previous post....

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 11 of 24
bradeneuropeArthur
in reply to: Anonymous

Hi,

Comment in red:

 

I am using Inventor 2017 Professional.  When I make an iPart with multiple solid bodies the 'Make Components' button is greyed out like in the screenshot. In inventor 2018 also. Are you saying that in 2018 this feature is available?  No If so that's very frustrating since we won't be upgrading to 2018 for several months at my company.

 

Would you like to create components (Derive parts) from the factory?

This is not possible also not with coding, because the I-part factory represents one of the members.

if you like to create components (Derive parts) from the member then this is a complete other story. 

for I parts that have been created as multi body can be create components when the table has been broken.

then the create components I visible again. So this is out of the box inventor and no coding needed.

I cannot show you how this is to be done (only by writing) because of the higher inventor version.

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 12 of 24

The following...

Ipart.PNG

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 13 of 24
Anonymous
in reply to: bradeneuropeArthur

Forgive me, I'm certain that you are very well versed in iLogic and Inventor in general, but I find it very unlikely that what I want can't be done with code, since I can do the entire process manually, exactly as I want.  

 

What I've been doing is this:

 

1. Start a new part

2. Click derive button

3. Choose one of the generated member files as the derive parent

4. In the derived part options, choose only one of the solid bodies

5. Save that derived part with a certain suffix.

6. Repeat steps 1-5, choosing the next solid body the next time through, until all solid bodies have been derived.

7. Create a new assembly that contains all derived parts.

 

All of this is essentially what the Make Components button does, except it is not available for iParts.  I want to write an iLogic rule that performs all of the steps written above, automating the process.  The fact that I can do all of that manually makes me almost certain it can be done with iLogic, I just don't have the knowledge of how to do it.  Regardless, thank you for all the help you've been giving me bradeneurope.

Message 14 of 24
bradeneuropeArthur
in reply to: Anonymous

I will take a look if I can guide you in the right direction ASAP. I need to investigate first. Is this fine by you?

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 15 of 24
Anonymous
in reply to: bradeneuropeArthur

Absolutely! I'm grateful for all the help you've given me already.
Message 16 of 24
basnederveen
in reply to: Anonymous

Hi,

 

I use a script in VBA to do this, but from a regular part. Since I do create a new part and derive each solid separately I think it will also work for your case, but you will have to make some edits.

 

I've remove some stuff you don't need, you do need to fill in your assembly since I was using some function that would find one that was opened and visible at the time. You can create one by saying documents.add instead of open. You can save your assembly using the same code i use when I save the part.

 

Also dont forget to fill ur part/assembly templates

 

Sub MakePart()
        
    ' set a reference to the active partdocument
    Dim prt As PartDocument
    Set prt = ThisApplication.ActiveDocument

Dim template As String
Dim folder As String template = "set your template" folder = PathName(prt.fullFileName) ' create an object collection to store the parts to put in assembly Dim prtCol As ObjectCollection Set prtCol = ThisApplication.TransientObjects.CreateObjectCollection
dim a as integer: a=0
' loop through the filtered selection Dim sb As SurfaceBody For Each sb In prt.componentdefinition.SurfaceBodies ' create a new part to derive the solid body in Dim newPart As PartDocument Set newPart = ThisApplication.Documents.Add(kPartDocumentObject, template, True) ' set a reference to the derivedpartcomponents Dim dpcs As DerivedPartComponents Set dpcs = newPart.ComponentDefinition.ReferenceComponents.DerivedPartComponents ' create the scale definition Dim dpd As DerivedPartUniformScaleDef Set dpd = dpcs.CreateUniformScaleDef(prt.fullFileName) ' set the settings in another sub 'Call settingsDerivedPart(dpd, sb) Call dpcs.Add(dpd) Call prtCol.Add(newPart) ' set the part title to the solidbodies name newPart.PropertySets.Item("Inventor Summary Information").Item("Title").Value = sb.Name 'sb.CreatedByFeature.Name
a=a+1
' Save the part ThisApplication.SilentOperation = True Call newPart.SaveAs(folder & sb.name & a & ".ipt", False) ThisApplication.SilentOperation = False Next sb ' find opened assembly in which the sketch part is Dim asm As AssemblyDocument Set asm = ThisApplication.Documents.Open("ADD YOUR ASSEMBLY FULLFILENAME") ' place in assembly? Set prt = Nothing For Each prt In prtCol ' create an empty matrix Dim mx As Matrix Set mx = ThisApplication.TransientGeometry.CreateMatrix() Call asm.ComponentDefinition.Occurrences.AddByComponentDefinition(prt.ComponentDefinition, mx) Call prt.Close(True) Next End Sub

Function PathName(FullPath As String) As String

' return all left of last \
PathName = Left(FullPath, InStrRev(FullPath, "\"))

End Function

 

Message 17 of 24
Anonymous
in reply to: basnederveen

Thank you so much basnederveen!  This code is a great help, and I'm much closer to a solution now.  I've been working on this code a bit but some things aren't working quite right.  

 

Everything is getting saved as I wanted now with the proper names, but the code only derives the first solid body each time it goes through the loop, rather than moving on to the next solid each time.

 

Also, I get an error message when it tries to place those parts in an assembly that reads:

Error in rule: Derive Parts from Solid Bodies 4, in document: MSB DER Test.ipt

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

If only the first of those two issues is fixed, this code will be a huge help to me.  If you can help me actually place those parts in an assembly I will be very grateful.

 

Sub Main()
        
    ' set a reference to the active partdocument
    Dim prt As PartDocument
    'Set prt = ThisApplication.ActiveDocument
	prt = ThisApplication.ActiveDocument

    'Set up folder that part is stored in, as well as default template.
	Dim template As String
    Dim folder As String
    template = "F:\Drafting & Design\The Box\Inventor\Templates\Standard.ipt"
    folder = PathName(prt.fullFileName)
    
	Dim oName As String
	oName = ThisDoc.FileName(False) 'without extension
	
	MessageBox.Show("This file name is: " & oName, "Title")

	
	'MessageBox.Show("Folder is: " & folder, "Title")
	
    ' create an object collection to store the parts to put in assembly
    Dim prtCol As ObjectCollection
    'Set prtCol = ThisApplication.TransientObjects.CreateObjectCollection
    prtCol = ThisApplication.TransientObjects.CreateObjectCollection
	
   'Setting loop counter
	Dim a As Integer: a=0

    ' loop through the filtered selection
    Dim sb As SurfaceBody
    For Each sb In prt.componentdefinition.SurfaceBodies
    
        ' create a new part to derive the solid body in
        Dim newPart As PartDocument
        'Set newPart = ThisApplication.Documents.Add(kPartDocumentObject, template, True)
        newPart = ThisApplication.Documents.Add(kPartDocumentObject, template, True)
		
        ' set a reference to the derivedpartcomponents
        Dim dpcs As DerivedPartComponents
        'Set dpcs = newPart.ComponentDefinition.ReferenceComponents.DerivedPartComponents
        dpcs = newPart.ComponentDefinition.ReferenceComponents.DerivedPartComponents
					
        ' create the scale definition
        Dim dpd As DerivedPartUniformScaleDef
        'Set dpd = dpcs.CreateUniformScaleDef(prt.fullFileName)
		dpd = dpcs.CreateUniformScaleDef(prt.fullFileName)
                  
        ' set the settings in another sub
        'Call settingsDerivedPart(dpd, sb)
        Call dpcs.Add(dpd)
        Call prtCol.Add(newPart)
  
        ' set the part title to the solidbodies name
        'newPart.PropertySets.Item("Inventor Summary Information").Item("Title").Value = sb.Name 'sb.CreatedByFeature.Name
      		  
        a=a+1  
		
		Dim suffix As String
		
		If a = 1
		suffix = "WEB"
		End If
		
		If a = 2
		suffix = "TF"
		End If
		
		If a = 3
		suffix = "BF"
		End If
		
        ' Save the part
        ThisApplication.SilentOperation = True
        'Call newPart.SaveAs(folder & sb.Name & " " & suffix & ".ipt", False)
		Call newPart.SaveAs(folder & oName & " " & suffix & ".ipt", False)
        ThisApplication.SilentOperation = False
    Next sb

	MessageBox.Show("I finished going through all the parts.", "Title")


    ' find opened assembly in which the sketch part is
    Dim asm As AssemblyDocument
    'Set asm = ThisApplication.Documents.Open("ADD YOUR ASSEMBLY FULLFILENAME") 
	asm = ThisApplication.Documents.Add(kAssemblyDocumentObject, folder, True)
	
    
    ' place in assembly?
    'Set prt = Nothing
	prt = Nothing
    For Each prt In prtCol
    
        ' create an empty matrix
        Dim mx As Matrix
        'Set mx = ThisApplication.TransientGeometry.CreateMatrix()
		mx = ThisApplication.TransientGeometry.CreateMatrix()
                
        Call asm.ComponentDefinition.Occurrences.AddByComponentDefinition(prt.ComponentDefinition, mx)
        Call prt.Close(True)
    Next
End Sub

Function PathName(FullPath As String) As String
 
 ' return all left of last \
 PathName = Left(FullPath, InStrRev(FullPath, "\"))

End Function

 

 

Message 18 of 24
basnederveen
in reply to: Anonymous

Ah I have this in a separate function, with some other derive settings. I
can send you this tomorrow morning. (Dutch time) basically its looping
through the derived part components and excluding all but the current one.
Message 19 of 24
Anonymous
in reply to: basnederveen

That would be brilliant, thanks!
Message 20 of 24
basnederveen
in reply to: Anonymous

Hi Java,

 

Here's the code with disabling the other solids. I do not know what is happening when you are placing the parts in an assembly. Maybe you can try opening the VBA editor (Alt-F11) and pasting it there, and then running the code? 

 

If you need to modify the code to open each part and do this, it's also not that difficult. Let me know.

 

Sub MakePart()
        
    ' set a reference to the active partdocument
    Dim prt As PartDocument
    Set prt = ThisApplication.ActiveDocument

    Dim template As String
    Dim folder As String
    template = ""
    folder = PathName(prt.fullFileName)
    
    ' create an object collection to store the parts to put in assembly
    Dim prtCol As ObjectCollection
    Set prtCol = ThisApplication.TransientObjects.CreateObjectCollection
    
    Dim a As Integer: a = 0

    ' loop through the filtered selection
    Dim sb As SurfaceBody
    For Each sb In prt.ComponentDefinition.SurfaceBodies
    
        ' create a new part to derive the solid body in
        Dim newPart As PartDocument
        Set newPart = ThisApplication.Documents.Add(kPartDocumentObject, template, True)
        
        ' set a reference to the derivedpartcomponents
        Dim dpcs As DerivedPartComponents
        Set dpcs = newPart.ComponentDefinition.ReferenceComponents.DerivedPartComponents
                    
        ' create the scale definition
        Dim dpd As DerivedPartUniformScaleDef
        Set dpd = dpcs.CreateUniformScaleDef(prt.fullFileName)
                  
        ' set the settings in another sub
        Call settingsDerivedPart(dpd, sb)
        Call dpcs.Add(dpd)
        Call prtCol.Add(newPart)
  
        ' set the part title to the solidbodies name
        newPart.PropertySets.Item("Inventor Summary Information").Item("Title").Value = sb.Name 'sb.CreatedByFeature.Name
      
        a = a + 1

        ' Save the part
        ThisApplication.SilentOperation = True
        Call newPart.SaveAs(folder & sb.Name & "_" & a & ".ipt", False)
        ThisApplication.SilentOperation = False
        
    Next sb

    ' find opened assembly in which the sketch part is
    Dim asm As AssemblyDocument
    Set asm = ThisApplication.Documents.Add(kAssemblyDocumentObject)
    
    ' place in assembly?
    Set prt = Nothing
    For Each prt In prtCol
    
        ' create an empty matrix
        Dim mx As Matrix
        Set mx = ThisApplication.TransientGeometry.CreateMatrix()
        
        Dim occ As ComponentOccurrence
        Set occ = asm.ComponentDefinition.Occurrences.AddByComponentDefinition(prt.ComponentDefinition, mx)
        Call prt.Close(True)
        
    Next
End Sub

Function PathName(FullPath As String) As String
 
 ' return all left of last \
 PathName = Left(FullPath, InStrRev(FullPath, "\"))

End Function
Sub settingsDerivedPart(ByRef dpd As DerivedPartUniformScaleDef, sb As SurfaceBody)
   
    ' set the derive style
    'dpd.DeriveStyle = kDeriveAsSingleBodyNoSeams
    'dpd.UseColorOverridesFromSource = False
    Call dpd.ExcludeAll
    
    ' include solid, exclude the others
    Dim dpe As DerivedPartEntity
    For Each dpe In dpd.Solids
        If dpe.ReferencedEntity.Name = sb.Name Then
            dpe.IncludeEntity = True
        End If
    Next
        
End Sub

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

Post to forums  

Autodesk Design & Make Report