ilogic to change drawing custom iproperty in each drawing inside assembly file

ilogic to change drawing custom iproperty in each drawing inside assembly file

Charlies_3D_T
Advocate Advocate
399 Views
4 Replies
Message 1 of 5

ilogic to change drawing custom iproperty in each drawing inside assembly file

Charlies_3D_T
Advocate
Advocate

Hello,

 

I was wondering if someon can help me out with the following problem.

 

I have a custom iproperty Executieklass

I want to change this from 1 to 2 or from 2 to 1. 

I want to choose this inside an assembly that it searches each drawing and opens it and changes the iproperty and closes it again.

 

I have a working rule to open the drawings but for some reason it's not chaning the iproperty.

 

My code below.

 

Sub Main()  
    ' Get the active assembly. 
    Dim oAsmDoc As AssemblyDocument 
    oAsmDoc = ThisApplication.ActiveDocument
	
	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))
	
	Dim newPath As String = IPJ_Folder_Location
	
	oDisplayName = oAsmDoc.DisplayName & ".dwg"

	Dim oDrwPath As String 
	oDrwPath = newPath + "5. DWG & IDW\"
	
    ' Get all of the referenced documents. 
    Dim oRefDocs As DocumentsEnumerator 
    oRefDocs = oAsmDoc.AllReferencedDocuments 

    ' Iterate through the list of documents. 
    Dim oRefDoc As Document 
    For Each oRefDoc In oRefDocs 
      
    'Dim oDrwName As String = oRefDoc.ReferencedDocumentDescriptor.ReferencedDocument.Displayname 	  
    oDisplayName = oRefDoc.DisplayName & ".dwg"
	
	Dim fList = System.IO.Directory.GetFileSystemEntries(oDrwPath, "*.dwg",System.IO.SearchOption.AllDirectories).Where(Function(X) X.Contains(oDisplayName))	
	
	
	If fList(0) <> String.Empty Then
		   
		
		Dim oDrwDoc As DrawingDocument
		oDrwDoc = ThisApplication.Documents.Open(fList(0), True)
		
            If iProperties.Value("Custom", "Executieklass") = "" Or iProperties.Value("Custom", "Executieklass") = "1" Then
                iProperties.Value("Custom", "Executieklass") = "2"
                Else
            End If

 		Call oDrwDoc.Close
	Else  	 
		MessageBox.Show(oDrwFile +" - Drawing is unavailable ")
	End If 
Next
		
End Sub
0 Likes
400 Views
4 Replies
Replies (4)
Message 2 of 5

Sergio.D.Suárez
Mentor
Mentor

Hi, I ask you, does your rule open the drawing files?
Or does your rule just not open them? Regards?
On the other hand, the names of your drawing files contain the extension ".ipt" or ".iam" in their name before ".dwg"? Because I see that in oDisplayname you have not deleted the file extension to only take its name.
I await your response. 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
Message 3 of 5

Charlies_3D_T
Advocate
Advocate
Hello,

It opens the drawing. But it's not changing the iproperty.
0 Likes
Message 4 of 5

Sergio.D.Suárez
Mentor
Mentor

Try making the following change to property access. When you access from the ilogic shortcuts it does so through the active document, that is, your assembly file, this method is safer to access the properties of another document

 

		Dim oDrwDoc As DrawingDocument
		oDrwDoc = ThisApplication.Documents.Open(fList(0), True)
		Dim oCustomProp As String = oDrwDoc.PropertySets.Item("Inventor User Defined Properties").Item("Executieklass").Value
		
            If oCustomProp = "" Or oCustomProp = "1" Then
                oCustomProp = "2"
                Else
            End If

 		Call oDrwDoc.Close

 


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
Message 5 of 5

Charlies_3D_T
Advocate
Advocate

@Sergio.D.Suárez 

 

Hello,

 

Still not working 😞

0 Likes