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: 

How to run a rule in a part file from a rule in the drawing file

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
ris.k.m.l
1404 Views, 5 Replies

How to run a rule in a part file from a rule in the drawing file

Hello,

 

I am trying to use iLogic to help me create the file types I need to give to my vendors once I have created a drawing.

In the .idw file I have a rule that creates a .pdf file and .dwg file. I also want it to activate a rule I have in the .ipt file that creates a .dxf file. Any ideas?

 

.idw code

 

trigger = iTrigger0
oType=Left(ThisDoc.FileName(False),3)
GoExcel.Open("S:\DRAWINGS\Folder Types.xlsx", "Sheet1")
For rowPN = 1 To 200
 If (GoExcel.CellValue("A" & rowPN) = oType) Then
    oFile = GoExcel.CellValue("C" & rowPN) 
         Exit For 
 End If
Next
oFolder = "S:\DRAWINGS\NOT RELEASED\" & oFile
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
ThisDoc.Document.SaveAs(oFolder & "\" & ThisDoc.FileName(False) & (".pdf") , True)
ThisDoc.Document.SaveAs(oFolder & "\" & ThisDoc.FileName(False) & (".dwg") , True)
oSM=ThisDoc.PathAndFileName(False)&".ipt"
iLogicVb.RunRule(oSM,"DXF")
MessageBox.Show(oFolder, "File Saved To")

 

.ipt code

Sub Main
ExportDxf()
End Sub
Public Sub ExportDxf()
oType=Left(ThisDoc.FileName(False),3)
GoExcel.Open("S:\DRAWINGS\Folder Types.xlsx", "Sheet1")
For rowPN = 1 To 200
 If (GoExcel.CellValue("A" & rowPN) = oType) Then
    oFile = GoExcel.CellValue("C" & rowPN) 
         Exit For 
 End If
Next
oFolder = "S:\DRAWINGS\NOT RELEASED\" & oFile
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
    Dim oDoc As PartDocument
    oDoc = ThisApplication.ActiveDocument
    Dim oCompDef As SheetMetalComponentDefinition
    oCompDef = oDoc.ComponentDefinition
    If oCompDef.HasFlatPattern = False Then
        oCompDef.Unfold
    Else
        oCompDef.FlatPattern.Edit
    End If
	sFname = oFolder & "\" & ThisDoc.FileName(False) & ".dxf"
	sOut = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=0&InteriorProfilesLayer=0&InvisibleLayers=IV_UNCONSUMEND_SKETCHES;IV_ALTREP?_BACK;IV_ALTREP_FRONT;IV_ARC_CENTERS;IV_TOOL_CENTE?R_DOWN;IV_TOOL_CENTER;IV_ROLL;IV_TANGENT;IV?_BEND;IV_BEND_DOWN;IV_ROLL_TANGENT;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN&SplineTolerance Double 0.01"
    oCompDef.DataIO.WriteDataToFile( sOut, sFname)
End Sub

 

5 REPLIES 5
Message 2 of 6
thomaskennedy
in reply to: ris.k.m.l

This should work for you :

 

Dim iLogicAuto As Object = iLogicVb.Automation
If (iLogicAuto Is Nothing) Then Exit Sub

Dim doc As Document = ThisDrawing.ModelDocument

Dim ruleName As String = "test"
Dim rule As Object = iLogicAuto.GetRule(doc, ruleName) 'get the rule
Dim i As Integer = iLogicAuto.RunRuleDirect(rule) 'run the rule

 

That rule will :

 

- Get the first model document in the drawing

- Defines a rule name (the rule to be fired in the ipt)

- Gets the rule

- Fires the rule.

 

Hope this helps,

Tom

Message 3 of 6
ris.k.m.l
in reply to: thomaskennedy

Hello Tom,

 

I tried using that code, it works to pull and run the rule in the .ipt file but I get a error now.

I do not get this error when I run the rule directly from the .ipt file.

 

Error Message:

Error in rule: Rule1, in document: K550008.ipt

Unable to cast COM object of type 'Inventor._DocumentClass' to interface type 'Inventor.PartDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D463-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 

Any ideas of what is going on? I am not a great programmer and this error is confusing me.

Message 4 of 6
thomaskennedy
in reply to: ris.k.m.l

Ah OK, try changing this line in your ipt :

 

oDoc = ThisApplication.ActiveDocument

 

to :

 

oDoc = ThisDoc.Document

 

ThisDoc.Document gets the document that the rule is in, whereas ThisApplication.ActiveDocument gets the active document, which in this case would've been your drawing document.

 

Does that work?

Message 5 of 6
ris.k.m.l
in reply to: thomaskennedy

Thanks.

That did the trick.

Message 6 of 6
tuliobarata
in reply to: ris.k.m.l

Would be possible to activate one rule in each part of one assembly that is the base view of th eIDW ?

 

Like if i put one registry in a part list, and then it runs a rule on each ipt to create a custom property with this registry, is that possible ? My problem here is how to make this link with one specific field of the parts list.

 

Thanks

Túlio Barata

IV 2013

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

Post to forums