Need a rule to run a program in derived part.

Need a rule to run a program in derived part.

Anonymous
Not applicable
362 Views
1 Reply
Message 1 of 2

Need a rule to run a program in derived part.

Anonymous
Not applicable

Hi All,

By using a ilogic rule I created a derived part from an assembly.

Ilogic rule used is mentioned below.

Try
    Dim g_App As Inventor.InventorServer = ThisApplication
    Dim AssDoc As Inventor.AssemblyDocument= ThisDoc.Document

    ' Create a new part document that will be the shrinkwrap substitute
    Dim oPartDoc As PartDocument
    oPartDoc = g_App.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , True)

    Dim oPartDef As PartComponentDefinition
    oPartDef = oPartDoc.ComponentDefinition

    Dim oDerivedAssemblyDef As DerivedAssemblyDefinition
    oDerivedAssemblyDef = oPartDef.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(AssDoc.FullDocumentName)
    ' Set various shrinkwrap related options
    oDerivedAssemblyDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsMultipleBodies
    oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = DerivedComponentOptionEnum.kDerivedExcludeAll
    oDerivedAssemblyDef.IncludeAllTopLevelSketches = DerivedComponentOptionEnum.kDerivedExcludeAll
    oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = DerivedComponentOptionEnum.kDerivedExcludeAll
    oDerivedAssemblyDef.IncludeAllTopLevelParameters = DerivedComponentOptionEnum.kDerivedExcludeAll
    Call oDerivedAssemblyDef.SetHolePatchingOptions(DerivedHolePatchEnum.kDerivedPatchNone)
    Call oDerivedAssemblyDef.SetRemoveByVisibilityOptions(DerivedGeometryRemovalEnum.kDerivedRemoveNone)
    Dim oDerivedAss As DerivedAssemblyComponent
    oDerivedAss = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAssemblyDef)
    
    ' Save the part
    Dim partname As String=ThisDoc.PathAndFileName(False)& ".ipt"
    ThisApplication.ActiveView.Fit
    ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute
    Call oPartDoc.SaveAs(partname ,  False)
Catch ex As Exception
        ErrorMessage = "Error creating ipt file."
End Try

After creating derived part, I want to run the below program automatically in the derived part.
Dim oDoc As PartDocument 
oDoc = ThisApplication.ActiveDocument 
Dim oDef As PartComponentDefinition 
oDef = oDoc.ComponentDefinition
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
Dim oAxis As WorkAxes
Dim oWPlane As WorkPlane
Dim FlatAngle As Double = Math.PI / 6
Dim NoSides As Integer = 12
Dim oSketch As PlanarSketch	
'initialize counter
Work1 = 1 ul
Work2 = (NoSides / 2 ul) + Work1
oAxis= oDef.WorkAxes
oWPlane = oDef.WorkPlanes.AddByLinePlaneAndAngle(oAxis("X Axis"), oDef.WorkPlanes("XZ Plane"), 0 deg)
oWPlane.Name = CStr(Work1) & "-" & CStr(Work2) & " Plane"
Dim oWPName As String = oWPlane.Name 
oWPlane.AutoResize = True
oWPlane.Visible = False
oSketch = oDef.Sketches.Add(oWPlane)
    oSketch.Name = "My_Sketch" & oWPName
    oSketch.ProjectedCuts.Add()
	oSketch.Visible = True
InventorVb.DocumentUpdate()
 
For Work1 = 2 To NoSides 
	Work2 = (NoSides / 2 ul) + Work1
	oWPlane = oDef.WorkPlanes.AddByLinePlaneAndAngle(oAxis("X Axis"), oDef.WorkPlanes(oWPName), FlatAngle/2)
    oWPlane.Name = CStr(Work1 + NoSides) & "-" & CStr(Work2 + NoSides) & " Plane"
	oWPName = oWPlane.Name
    oWPlane.AutoResize = True
    oWPlane.Visible = False
	oSketch = oDef.Sketches.Add(oWPlane)
    oSketch.Name = "My_Sketch" & oWPName
    oSketch.ProjectedCuts.Add()
	oSketch.Visible = True
Next


 

 

 

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

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

You could create a template with the rule inside it and use that when creating your part. Then execute the rule from main assembly code with

iLogicVb.Automation.RunRule(oPartDoc, "rulename")

Or you could create the rule in the part from main assembly code

Dim oRule As iLogicRule = iLogicVb.Automation.AddRule(oPartDoc, "PartRule", "Rule text")

and then execute it as described above.

To create the new part from a template simply use the optional argument TemplateFileName in the Documents.Add-function 🙂

0 Likes