ilogic PartMakeComponentsCmd

ilogic PartMakeComponentsCmd

simone.custodi
Explorer Explorer
559 Views
1 Reply
Message 1 of 2

ilogic PartMakeComponentsCmd

simone.custodi
Explorer
Explorer

Hi everyone, I need help with an ilogic rule: I have my PART file with multi solid and I would like to create an assembly according to my template.
I started like this:

 

ThisApplication.CommandManager.ControlDefinitions.Item ("PartMakeComponentsCmd"). Execute
'define the document as a component definition
Dim oCompDef As ComponentDefinition
oCompDef = ThisDoc.Document.ComponentDefinition

'define the solidbody
Dim oBody As SurfaceBody

'define the solid body name to look for
'Dim body As String

i = 1
For Each SurfaceBody In oCompDef.SurfaceBodies
oBody = oCompDef.SurfaceBodies.Item (i)

ThisApplication.CommandManager.DoSelect (obody)

i = i +1
Next

 

Then I stop because I don't know how to name the target assembly and set the template.

 

Thanks for your help.

0 Likes
Accepted solutions (1)
560 Views
1 Reply
Reply (1)
Message 2 of 2

JhoelForshav
Mentor
Mentor
Accepted solution

@simone.custodi 

I'd say your best option would be to create your own "Make Components"-function in iLogic instead of calling the controldefinition.

See example below.

You'll get prompted to save the assembly and then the parts will be saved in the same directory.

In this code I use the template names:

Standard.iam

Standard.ipt

Sheet Metal.ipt

If your templates have different names you must replace the names in the code.

Try it and let me know how it works for you 🙂

 

If ThisDoc.PathAndFileName(False) = ""
	MessageBox.Show("Save multibody part before running this rule!", "Part is not saved", _
	MessageBoxButtons.OK, MessageBoxIcon.Error)
	Exit Sub
End If
Dim oFileDlg As Inventor.FileDialog
ThisApplication.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Assembly files|*.iam"
oFileDlg.CancelError = False
oFileDlg.OptionsEnabled = False
oFileDlg.ShowSave
If oFileDlg.FileName = "" Then Exit Sub
Dim oAsm As AssemblyDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject, _
ThisApplication.DesignProjectManager.ActiveDesignProject.TemplatesPath & "Standard.iam", True)
oAsm.FullFileName = oFileDlg.FileName
Dim oDoc As PartDocument = ThisDoc.Document
Dim oSurfBods As SurfaceBodies = oDoc.ComponentDefinition.SurfaceBodies
For Each oBod As SurfaceBody In oSurfBods
	Dim oPart As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, If (TypeOf (oBod.ComponentDefinition) Is SheetMetalComponentDefinition, _
	ThisApplication.DesignProjectManager.ActiveDesignProject.TemplatesPath & "Sheet Metal.ipt", ThisApplication.DesignProjectManager.ActiveDesignProject.TemplatesPath & "Standard.ipt"), False) 
	Dim DerComps As DerivedPartComponents = oPart.ComponentDefinition.ReferenceComponents.DerivedPartComponents
	Dim DerDef As DerivedPartDefinition = DerComps.CreateUniformScaleDef(oDoc.FullFileName)
	For Each oSolid As DerivedPartEntity In DerDef.Solids
		oSolid.IncludeEntity = If (oSolid.ReferencedEntity Is oBod, True, False)
	Next
	DerComps.Add(DerDef)
	If TypeOf (oPart.ComponentDefinition) Is SheetMetalComponentDefinition
		Try
			oPart.ComponentDefinition.SheetMetalStyles(oDoc.ComponentDefinition.GetBodySheetMetalStyle(oBod).Name).Activate
		Catch
		End Try
	End If
	Dim i As Integer = 0
	While True
		Try
			If i = 0
				oPart.SaveAs(System.IO.Path.GetDirectoryName(oFileDlg.FileName) & "\" & oBod.Name & ".ipt", False)
			Else
				oPart.SaveAs(System.IO.Path.GetDirectoryName(oFileDlg.FileName) & "\" & oBod.Name & "_" & i & ".ipt", False)
			End If
			Exit While
		Catch
			i += 1
		End Try
	End While
	oAsm.ComponentDefinition.Occurrences.Add(oPart.FullFileName, ThisApplication.TransientGeometry.CreateMatrix).Grounded = True
Next
oAsm.Activate
0 Likes