Write parameters to multiple drawings

Write parameters to multiple drawings

Anonymous
Not applicable
531 Views
2 Replies
Message 1 of 3

Write parameters to multiple drawings

Anonymous
Not applicable

I am trying to automate the text input required when starting a new project. There are certain pieces of information such as the job number, author, creation date etc. that are common to all drawings. I can do this easily from the Inventor API but I am trying to do it from an iLogic rule to simplify it for other designers.

 

Right now the iLogic rule is located in one of the drawings which filters down to the assembly that I am manipulating. I am collecting the variables from an excel sheet that acts as the design sheet. The excel sheet is accessed via filename and path, stores the information in an array which is then available for use within the drawing and the containing assemblies and parts which works very well.

 

Ideally I would like to push some of these gathered parameters to other open drawings for the project so I do not have to open them and run a similar rule just to gather and write information that has already been gathered in this rule.

 

This is the code I am using to access each open drawing:

Dim oDoc As Document
Dim oDocSet As DocumentsEnumerator
Dim oActiveDoc As Inventor.Document
oActiveDoc = ThisApplication.ActiveDocument
oDocSet = ThisApplication.Documents.VisibleDocuments
oDocCheck = Len(ShortJobNumber)

ThisApplication.ScreenUpdating = False
    For Each oDoc In oDocSet
        If oDoc.DocumentType = kDrawingDocumentObject Then
            If Left(oDoc.DisplayName,oDocCheck) = ShortJobNumber Then
				oDoc.activate
				MessageBox.Show(oDoc.displayname, "Title")
				
				oDoc.PropertySets.Item("Inventor User Defined Properties", "JobNumber")= JobNumber
oDoc.PropertySets.Item("Design Tracking Properties").Item("Designer") = DrawingInitials
'iProperties.Value(oDoc.displayname,"Inventor User Defined Properties", "JobNumber") = JobNumber

End If
End If
Next
oActiveDoc.Activate
ThisApplication.ScreenUpdating = True

I have tried several ways to access the iProperties but it either returns "Cant Find .idw" or it tells me that the property I am trying to access is read only. 

 

It appears that I only have access to write parameters to documents directly related to the one the rule is contained in? Is there any way to do this or maybe to pass a variable from this rule to a rule in the other drawings that would be triggered by this rule?

 

Any ideas would be appreciated, thanks!

 

0 Likes
Accepted solutions (2)
532 Views
2 Replies
Replies (2)
Message 2 of 3

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hello, here is an example of a rule that takes the path of the file that you have active, and searches all the idw within the folder that contains the original file, then opens each of these idw and changes the description property, then he saves them and finally closes them.

 

Dim processPath As String 
processPath = ThisDoc.Path  '''Specify the path of the folder

Dim drawings () As String = System.IO.Directory.GetFiles(processPath,"*.idw",System.IO.SearchOption.AllDirectories) 	
	
For Each drawing As String In drawings 
	Dim oDoc As Document
	oDoc = ThisApplication.Documents.Open(drawing, True)
	Dim oDescription As String
	oDescription = "Description123"
	oDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value = oDescription
	oDoc.Save
	oDoc.Close
Next

 Be careful you can initially delete the lines to save and close the document to verify that you perform the action you want, because if there are many documents and there is a failure, you will keep the error in each of those documents and you should correct them one by one .
Once you make sure everything works well you can try to change the line to

 

oDoc = ThisApplication.Documents.Open(drawing, False)

 

To open it in hidden mode and see if you can perform the action correctly, it will be faster and more efficient if it works well.

I hope it gives you the way so you can solve your problem


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

Message 3 of 3

Anonymous
Not applicable
Accepted solution

Looks like I was very close... I was missing this syntax:

oDoc.PropertySets.Item("Inventor User Defined Properties").Item("JobNumber").value= JobNumber

Thanks for the quick response!!