iLogic rule runs in .iam but will flag an error if drawing file is open

iLogic rule runs in .iam but will flag an error if drawing file is open

Anonymous
Not applicable
471 Views
2 Replies
Message 1 of 3

iLogic rule runs in .iam but will flag an error if drawing file is open

Anonymous
Not applicable

I have a rule which inserts the 'z' value of the bounding box for each part in an assembly into the iproperty value 'vendor'

 

this works fine when I run it in the assembly level, but if I happen to have a drawing file open, it will reprt an error. 

 

I cant understand why......any help?

 

Version:1.0 StartHTML:00000145 EndHTML:00004951 StartFragment:00000294 EndFragment:00004919 StartSelection:00000294 EndSelection:00000294SyntaxEditor Code Snippet

'Find all parts in this assembly that contain parameter name G_L
'Convert the boundary box z dimension into an iProperty
 
fmgr = ThisApplication.FileManager
For Each file In fmgr.files
    doc = ThisApplication.Documents.ItemByName (file.fullfileName)
    compdef = doc.ComponentDefinition
    If (doc.documenttype = 12291) Then 'Only do this for assembly or subassembly
   
        For Each occ In compdef.Occurrences
            If (occ.definition.type = 83886592) Then 'Only do this for part
               
                Try     'Look for existance of G_L parameter
                    TempG_L = Parameter(occ.Name, "G_L")
                Catch   'Part does not contain G_L
                    GoTo skipThisPart
                End Try 'Found a file containing G_L
				
		templen = Round(10*(occ.definition.RangeBox.MaxPoint.Z - occ.definition.RangeBox.MinPoint.Z),1)
				
		templen = Ceil(templen) 'Rounds the result to next whole number
                
                'Push this number value into an unused iProperty           
                iProperties.Value(occ.Name, "Project", "Vendor") = templen

            skipThisPart:
            End If
        Next occ
    End If
Next File
 
InventorVb.DocumentUpdate() 'Update the model
0 Likes
Accepted solutions (1)
472 Views
2 Replies
Replies (2)
Message 2 of 3

AlexFielder
Advisor
Advisor
Accepted solution

This is happening because as the error message states there is no ComponentDefinition on the DrawingDocument object:

2018-08-02 11_12_52-Autodesk Inventor Professional 2019 - [Frame Example.iam].png

 

One way to fix this is to change your rule like so:

 

'Find all parts in this assembly that contain parameter name G_L
'Convert the boundary box z dimension into an iProperty
 
fmgr = ThisApplication.FileManager
For Each file In fmgr.Files
	Try
    doc = ThisApplication.Documents.ItemByName (File.fullfileName)
    compdef = doc.ComponentDefinition
    If (doc.documenttype = 12291) Then 'Only do this for assembly or subassembly
   
        For Each occ In compdef.Occurrences
            If (occ.definition.type = 83886592) Then 'Only do this for part
               
                Try     'Look for existance of G_L parameter
                    TempG_L = Parameter(occ.Name, "G_L")
                Catch   'Part does not contain G_L
                    GoTo skipThisPart
                End Try 'Found a file containing G_L
				
		templen = Round(10*(occ.definition.RangeBox.MaxPoint.Z - occ.definition.RangeBox.MinPoint.Z),1)
				
		templen = Ceil(templen) 'Rounds the result to next whole number
                
                'Push this number value into an unused iProperty           
                iProperties.Value(occ.Name, "Project", "Vendor") = templen

            skipThisPart:
            End If
        Next occ
    End If
	Catch
		Continue For
	End Try
Next File
 
InventorVb.DocumentUpdate() 'Update the model

🙂

 

Message 3 of 3

chandra.shekar.g
Autodesk Support
Autodesk Support

Good catch @AlexFielder,

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes