Hi there,
I have an iassembly which contains around 500 different members. There aren't any major differences between the members other than parts being Included/Excluded and parts being replaced by similar parts (this can all be done in the table as the parts are all created as one ipart family).
I need an assembly drawing for every member. As the drawings will be very similar, it is possible to just create one drawings then use 'Save as' and 'replace model reference' to create the whole lot. As this process would be very tedious and time consuming, I want to create a ilogic program or a VB macro to automate this process.
Basically i need a program that will...
FOR every line in the table (say 1 to 500)...
look at the currently active drawing...
replace model reference (for 2 views and a parts list) with the appropriate member (whos file name will match it's Part Number)...
save as with a file name that matches the current rows Part Number...
END when all of the members are complete.
Any help will be much appeciated. I have a moderate understanding of programming but as far as writting VB and ilogic goes, I could do with some major help.
Thanks,
Wayne Helley
Solved! Go to Solution.
Solved by Yijiang.Cai. Go to Solution.
It should be accomplished by API, and please use one iAssembly member to create one drawing template named "Template.idw", and open the drawing template, then run the code lines below -
Sub iAsmbDrawing()
Dim oDrawingDoc As DrawingDocument
Set oDrawingDoc = ThisApplication.ActiveDocument
Dim oMemberFile As String
' "xxx-0" is one portion of full file name of iAssembly member, e.g. "D:\\test-0"
For i = 1 To 500
'Get the full file name of iAssembly member
If i < 10 Then
oMemberFile = "xxx-0" & CStr(i)
Else
oMemberFile = "xxx-" & CStr(i)
End If
'replace the model
Call oDrawingDoc.ActiveSheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(oMemberFile & ".iam")
'Save copy as one new idw using the member name
Call oDrawingDoc.SaveAs(oMemberFile & ".idw", True)
Next
Call oDrawingDoc.Close(True)
End Sub
Thanks, this should help us out a huge amount!
As I have to stick to the company's part numbering system, I only need to make a slight change because my assembly names go from 09090G00104854 to 09090G00105382...
so if I am correct I can just use...
"For i = 4854 To 5382"
along with
"oMemberFile = "C:\ARTICULATE\09\090\09090GT0000023\09090G0010" & CStr(i)"
Many thanks again for your help,
Wayne
Hi, I am still having problems. When I run the code, An error is returned saying "Compile error: Variable not defined" when the code reaches " For i = 4854 To 4859". I have tried adding "Dim i As String" but then when the code reaches the same line, I get the error "Compile error: Type mismatch".
My code is as follows...
Option Explicit
Sub iAsmbDrawing()
Dim oDrawingDoc As DrawingDocument
Set oDrawingDoc = ThisApplication.ActiveDocument
Dim oMemberFile As String
' "xxx-0" is one portion of full file name of iAssembly member, e.g. "D:\\test-0"
For i = 4854 To 4859
'Get the full file name of iAssembly member
oMemberFile = "C:\ARTICULATE\09\090\09090GT0000023\09090G0010" & CStr(i)
'replace the model
Call oDrawingDoc.ActiveSheet.DrawingViews(1).Referenced?DocumentDescriptor.ReferencedFileDescriptor.Replac?eReference(oMemberFile & ".iam")
'Save copy as one new idw using the member name
Call oDrawingDoc.SaveAs(oMemberFile & ".idw", True)
Next
Call oDrawingDoc.Close(True)
End Sub
I have attached a jpg incase there is something completely wrong with how I am inputting the code.
Thanks,
Wayne
For this issue, please see the code line in red background in the image, which means that this code line is not well coded. And you could get some illegal chars like "?" in code line.
And for the variable "I", it should be defined as "Dim i as Integer". And you could also remove the first line "Option Explicit", which is used to detect which variables are not pre-defined.
I seem to have overcome this problem by adding "Dim i" but no I have an error that reads "Compile error: Syntax error" when I reach the line...
Call oDrawingDoc.ActiveSheet.DrawingViews(1).Referenced?DocumentDescriptor.ReferencedFileDescriptor.Replac?eReference(oMemberFile & ".iam")
I am not familiar with these functions so could it be a typing error?
Thanks,
Wayne
I have realised the question marks shouldn't have been there at all and must have appeared when i copied the code.
I ran the final code but Inventor crashed. I think it may have been due to restrictions due to Vault so I will try checking everything out then running it again.
Wayne
Thanks again for your help.
Much appreciated
The code seems to do it's job but Inventor tends to crash a couple of drawings in. I get the message "Autodesk Vault: Encountered an Improper Argument".
I have checked everything so that there are no restrictions and have also tried logging out of Vault before running the code. Not all the iassembly members may be up to date which could be part of the problem.
My code is as follows...
Sub iAsmbDrawing()
Dim oDrawingDoc As DrawingDocument
Set oDrawingDoc = ThisApplication.ActiveDocument
Dim i As Integer
Dim oMemberFile As String
' "xxx-0" is one portion of full file name of iAssembly member, e.g. "D:\\test-0"
For i = 4885 To 5382
'Get the full file name of iAssembly member
oMemberFile = "C:\ARTICULATE\09\090\09090GT0000023\09090G0010" & CStr(i)
'replace the model
Call oDrawingDoc.ActiveSheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(oMemberFile & ".iam")
'Save copy as one new idw using the member name
Call oDrawingDoc.SaveAs(oMemberFile & ".idw", True)
Next
Call oDrawingDoc.Close(True)
End Sub
Managed to solve the problem by adding a bit of code that adds a 5 second pause during the loop.
Wayne
You should delete the question marks populating your code
i.e. Call oDrawingDoc.ActiveSheet.DrawingViews(1).Referenced?DocumentDescriptor.ReferencedFileDescriptor.Replac?eReference(oMemberFile & ".iam")
Hi AHoward321,
I think those characters are placed automatically, but unintentionally when code is posted to the forum without using the Insert Code button.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com