Hello,
Is there a way to change an iProperty, specifically the iProperties->Project->Project field for multiple parts automatically.
I use the iLogic Design Copy Tool to copy over an entire project, and for the most part the only changes is the project number.
I didn't see a way to change this in the Design Copy Tool, possibly there is some other tools that can do this that I don't know about. But if not, I am assuming a small script (VBA??) would be required to do this? whether it is in Inventor or just an outside program to carry out this change.
I found this old thread, but it seems that people just found another way to do this?
My workflow would follow something like this:
-Use iLogic Design Copy Tool to copy over project to new folder
-Open up full assembly
-Run rule or script to update all parts in assembly with new Project iProperty
-Save
-update the drawings as I need, (they will all need to be reviewed as some parts will be modified anyways)
Any Ideas?
Thanks!
Solved! Go to Solution.
Solved by jdkriek. Go to Solution.
Hi Jonathan,
I have been playing around with iLogic(still in beginner mode). This is what I have come up with and it works perfectly, haha, however it only changes the Project iProperty for the top level assembly.
I need the rule to change the Project number through the entire assembly, meaning all the parts and the sub-assemblies and the parts within those sub-assemblies.
I hope this is possible, I'm sure it is, been digging around in these forums as well Curtis Waguespack's inventor trenches.
If you have any references for this, that would be great!
Thanks!
'used to trigger rule for testing or running the rule Trigger = iTrigger0 'ignores errors and continues on with the code On Error Resume Next newprojectname= InputBox("Enter New Project Number Below", "New Project Number", newprojectname) iProperties.Value("Project", "Project") = newprojectname RuleParametersOutput() iLogicVb.UpdateWhenDone = True
I managed to figure something out however the image below depicts how I feel:
Here is my adaptation of the code I linked to in the previous thread.
Dim openDoc As Inventor.Document Dim docFile As Inventor.Document Dim DrawingDoc As DrawingDocument Dim FNamePos As Long Dim docFName As String Dim iDesc as String DrawingDoc = openDoc openDoc = ThisApplication.ActiveDocument iDesc = iProperties.Value("Project", "Project") newprojectname= InputBox("Enter New Project Number Below", "New Project Number", newprojectname) For Each docFile In openDoc.AllReferencedDocuments 'change project iproperty for opened assmebly iProperties.Value("Project", "Project") = newprojectname 'change project iproperty in all part files of opened assembly If docFile.DocumentType = kPartDocumentObject Then FNamePos = InStrRev(docFile.FullFileName, "\", - 1) docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos) iProperties.Value(docFName, "Project", "Project") = newprojectname End If 'change project iproperty in all sub-assembly files of opened assembly If docFile.DocumentType = kAssemblyDocumentObject Then FNamePos = InStrRev(docFile.FullFileName, "\", - 1) docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos) iProperties.Value(docFName, "Project", "Project") = newprojectname End If Next iLogicVb.UpdateWhenDone = True
So what I got this to do was, to:
Prompt a message box for the user to input a new project number
Once it is entered, the opened assembly, all the parts inside that main assembly, all the parts inside the sub-assemblies and the sub-assemblies themselves have the Project iProperty filled.
I am understanding bit by bit, but I don't know what is going on in the first 9 lines, I know that it is declaring items or variables, but I can't for the life of me understand the logic behind this.
The next 4 lines make sense, as I added them, but this section here:
FNamePos = InStrRev(docFile.FullFileName, "\", - 1)
docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos)
iProperties.Value(docFName, "Project", "Project") = newprojectname
I have no idea what it is doing...
I am going to mark this thread solved eventually, but if anyone could explain these few short lines to me, it would be very awesome!!
Thanks!
EDIT:
This rule is ran in the main GA after project was copied to a new location using the iLogic Design Copy Tool.
I know that this means, for each project copied I will have duplciate file names, but that is why the Project code it critical as it defines which part belongs to which project incase of a mix up.
Now after running this rule, and updating the project iproperty in the part/assembly files, how would one update all the drawings so that the Project iProperty in the titleblock is updated. I was just going to do this manually, but if there is a way to do it, then I should probaly take advantage of the automation function.
Thanks again!!
Here you go 😃
This is adapted from Brian Ekins VBA code - I modified it for your purposes.
Paste it directly into a iLogic rule.
Sub Main() 'JDK 2013 Dim oAsmDoc As AssemblyDocument = ThisDoc.Document ' Get the project number from user ProjectNo = InputBox("Project Number", "Project", ProjectNo) ' Change Project iProperty in Main Assemblhy iProperties.Value("Project", "Project") = ProjectNo ' Call recursion function Call TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, 1, ProjectNo) Call oAsmDoc.Update End Sub Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, _ Level As Integer, ProjectNo As String) Dim oOcc As ComponentOccurrence For Each oOcc In Occurrences 'Change Project iProperty for all iProperties.Value(oOcc.Name, "Project", "Project") = ProjectNo ' Check to see if this occurrence represents a subassembly ' and recursively call this function to traverse through it. If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then Call TraverseAssembly(oOcc.SubOccurrences, Level + 1, ProjectNo) End If Next End Sub
So this is to replace my hodgepodge rule to change all Project iProperties within the opened Assembly?
Thanks!
I have been digging around but found nothing yet; is it possible to update an iProperty field in a drawing without opening it?
I can't find nothing on this topic.
My next move is to develop a script that would:
I think this can be accomplished.
Thanks!
Apprentice seems to be what I would require to change the iproperties of the Inventor files, however I think that I am in way over my head in regards to my current programming level. To be effectively use Inventor Customization, what specifically is the programming language VBA?
thanks for you help this far jdkriek! it is all very helpful!!
Straight from Autodesk's API:
Keep in mind that we only recommend using VBA for prototyping and learning the API but do not recommend using VBA in production.
While I still have a ton of VBA macros out there, the plan is STILL to convert to VB.NET add-ins and external iLogic.
OK, so one last question before I begin my quest into API Training:
What general steps would it take to edit iProperties of inventor files without opening them up? Not looking for specifics, just the general workflow.
Apprentice is not a program is how I interpreted it, you just use it gain access to Inventor file data by declaring it out in as an object?
Thanks!
Hello,
Your code worked perfectly, even I am also looking for this solution.
Thanks a lot for a posting this code.
Hi, I have been using this code for over 2 years, and it was very helpful. I have made iassembly with a members, and when I run the rule it changes project name of all parts, except members. Can you do a small change of line or two to make it work for members in iassembly also? Thx in front!!
Can't find what you're looking for? Ask the community or share your knowledge.