Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using ilogic or a macro to automate drawing creation of iassembly members

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
waynehelley
3768 Views, 11 Replies

Using ilogic or a macro to automate drawing creation of iassembly members

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

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
11 REPLIES 11
Message 2 of 12
Yijiang.Cai
in reply to: waynehelley

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,
River Cai

Inventor Quality Assurance Team
Autodesk, Inc.
Email: River-Yijiang.Cai@autodesk.com
Message 3 of 12
waynehelley
in reply to: Yijiang.Cai

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

 

 

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 4 of 12
waynehelley
in reply to: Yijiang.Cai

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

 

 

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 5 of 12
Yijiang.Cai
in reply to: waynehelley

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.

Thanks,
River Cai

Inventor Quality Assurance Team
Autodesk, Inc.
Email: River-Yijiang.Cai@autodesk.com
Message 6 of 12
waynehelley
in reply to: waynehelley

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

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 7 of 12
waynehelley
in reply to: waynehelley

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

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 8 of 12
waynehelley
in reply to: Yijiang.Cai

Thanks again for your help.

 

Much appreciated

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 9 of 12
waynehelley
in reply to: Yijiang.Cai

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

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Tags (1)
Message 10 of 12
waynehelley
in reply to: waynehelley

Managed to solve the problem by adding a bit of code that adds a 5 second pause during the loop.

 

Wayne

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 11 of 12
AHoward321
in reply to: waynehelley

You should delete the question marks populating your code

 

i.e. Call oDrawingDoc.ActiveSheet.DrawingViews(1).Referenced?DocumentDescriptor.ReferencedFileDescriptor.Replac?eReference(oMemberFile & ".iam")

Message 12 of 12

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

 

Insert Code button.PNG

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report