Inventor Customization

Reply
Active Member
ris.k.m.l
Posts: 9
Registered: ‎08-14-2012
Message 1 of 6 (358 Views)
Accepted Solution

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

358 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

 

Distinguished Contributor
thomaskennedy
Posts: 112
Registered: ‎09-27-2010
Message 2 of 6 (353 Views)

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
ris.k.m.l
Posts: 9
Registered: ‎08-14-2012
Message 3 of 6 (347 Views)

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
thomaskennedy
Posts: 112
Registered: ‎09-27-2010
Message 4 of 6 (345 Views)

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
ris.k.m.l
Posts: 9
Registered: ‎08-14-2012
Message 5 of 6 (342 Views)

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
tuliobarata
Posts: 164
Registered: ‎11-30-2007
Message 6 of 6 (296 Views)

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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube