Inventor Customization

Inventor Customization

Reply
Active Member
9 Posts
0 Kudos
Registered: ‎08-14-2012
Post 1 of 6
Accepted Solution

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

386 Views, 5 Replies
08-21-2012 06:46 AM

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

 

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?

Distinguished Contributor
113 Posts
23 Kudos
Registered: ‎09-27-2010
Post 2 of 6

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

08-21-2012 07:55 AM 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

Active Member
9 Posts
0 Kudos
Registered: ‎08-14-2012
Post 3 of 6

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

08-21-2012 08:22 AM 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.

Distinguished Contributor
113 Posts
23 Kudos
Registered: ‎09-27-2010
Post 4 of 6

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

08-21-2012 08:26 AM 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?

Active Member
9 Posts
0 Kudos
Registered: ‎08-14-2012
Post 5 of 6

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

08-21-2012 08:29 AM in reply to: thomaskennedy

Thanks.

That did the trick.

Mentor
164 Posts
8 Kudos
Registered: ‎11-30-2007
Post 6 of 6

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

10-10-2012 04:58 AM 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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!