Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Ilogic working local but not in external rules

Charlies_3D_T
Advocate

Ilogic working local but not in external rules

Charlies_3D_T
Advocate
Advocate

Hello,

 

The rule below works perfectly when i run it in a drawing. But when i place it in external rules and run it nothing happens. Someon an idea? 

Imports System.IO
Imports System.Collections
Imports System


Dim
IPJ As String Dim IPJ_Name As String Dim IPJ_Path As String Dim FNamePos As Long 'set a reference to the FileLocations object. IPJ = ThisApplication.FileLocations.FileLocationsFile 'get the location of the last backslash seperator FNamePos = InStrRev(IPJ, "\", -1) 'get the project file name with the file extension IPJ_Name = Right(IPJ, Len(IPJ) - FNamePos) 'get the project name (without extension) IPJ_ShortName = Left(IPJ_Name, Len(IPJ_Name) - 4) 'get the path of the folder containing the project file IPJ_Folder_Location = Left(IPJ, Len(IPJ) - Len(IPJ_Name)) oThisDoc = ThisDoc.Document If TYPE_PLAN = "Detailtekening" Then Extentie = ".ipt" Else If TYPE_PLAN = "Lassamenstelling" Or TYPE_PLAN = "Ssamenstelling" Then Extentie = ".iam" End If 'Full name of the to search .ipt or .ass' oThisFileName = ThisDoc.FileName(False) & Extentie Dim Folder As New IO.DirectoryInfo(IPJ_Folder_Location) Dim FileList As New List(Of String) For Each File As IO.FileInfo In Folder.GetFiles(oThisFileName,IO.SearchOption.AllDirectories) If File.FullName.Contains(oThisFileName) = True Then FileList.Add(File.FullName) NieuwFilePath = File.FullName doc = ThisDoc.Document 'Change the Referenced File' oFD = doc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor oFD.ReplaceReference(NieuwFilePath) Else MsgBox("the file " & oThisFileName & " not found in this project!") End If Next iLogicVb.UpdateWhenDone = True InventorVb.DocumentUpdate()

 

The problem is located that i can't get the custom propertie Type_Plan. Because when it's an external rule it doesn't read the prop. Someon knows how i can read that property? 

0 Likes
Reply
Accepted solutions (1)
772 Views
5 Replies
Replies (5)

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Think that you need to pass the active document to the external rule, Like:

 

Public Sub Main ()

External_Rule(ThisApplication. ActiveDocument)

End Sub

 

Public Sub External_Rule (Doc as Document)

 

End sub

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

0 Likes

Sergio.D.Suárez
Mentor
Mentor

I do not have the variables of your drawing file, so I can not test the rule in depth. But I want to ask you something ... Are you using the external rule in a new file? keep in mind that the line


oThisFileName = ThisDoc.FileName (False) & Extentie


it refers to the file in which the rule is made (which is supposed to be a drawing file, but in the if - then rules it specifies that it can be an ipt or a iam). If the file is not saved the filename will be "" nothing. I suppose that for this place the error should be, the access to the project file seems to be fine.
regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes

Charlies_3D_T
Advocate
Advocate

@Sergio.D.Suárez @bradeneuropeArthur 

 

Hello,

 

No the property Type_Plan is in all my drawings. But the strange thing is that it doesn't read it. So i need to know how to read it. 

 

Normaly you can use this: 

 

'define the property set
customPropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")

'---------------- find or create custom properties -------------
'look for the custom propety and add it if not found

oTest = customPropertySet.Item("TYPE_PLAN")

 

0 Likes

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Try to define the string as described in its example, as an external rule it worked for me.

 

Dim IPJ As String
Dim IPJ_Name As String
Dim IPJ_Path As String
Dim FNamePos As Long
'set a reference to the FileLocations object.
IPJ = ThisApplication.FileLocations.FileLocationsFile
'get the location of the last backslash seperator
FNamePos = InStrRev(IPJ, "\", -1)    
'get the project file name with the file extension
IPJ_Name = Right(IPJ, Len(IPJ) - FNamePos)
'get the project name (without extension)
IPJ_ShortName = Left(IPJ_Name, Len(IPJ_Name) - 4)
'get the path of the folder containing the project file
IPJ_Folder_Location = Left(IPJ, Len(IPJ) - Len(IPJ_Name))

oThisDoc = ThisDoc.Document

customPropertySet = oThisDoc.PropertySets.Item("Inventor User Defined Properties")
oTYPE_PLAN  = customPropertySet.Item("TYPE_PLAN").value

If oTYPE_PLAN = "Detailtekening" Then
Extentie = ".ipt"
'MessageBox.Show(Extentie)

Else If oTYPE_PLAN = "Lassamenstelling" Or oTYPE_PLAN = "Ssamenstelling" Then
Extentie = ".iam"
End If

'Full name of the to search .ipt or .ass'
oThisFileName = ThisDoc.FileName(False) & Extentie

Dim Folder As New IO.DirectoryInfo(IPJ_Folder_Location)
Dim FileList As New List(Of String)
For Each File As IO.FileInfo In Folder.GetFiles(oThisFileName,IO.SearchOption.AllDirectories)
            If File.FullName.Contains(oThisFileName) = True Then
               FileList.Add(File.FullName)
		       NieuwFilePath = File.FullName
			   doc = ThisDoc.Document
			   'Change the Referenced File'
               oFD = doc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
               oFD.ReplaceReference(NieuwFilePath)
		 	Else 
			MsgBox("the file " & oThisFileName & " not found in this project!")
            End If
Next
iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes

Charlies_3D_T
Advocate
Advocate

@Sergio.D.Suárez 

 

Now it's working thank you!

0 Likes