Inventor General Discussion

Reply
Distinguished Contributor
waynehelley
Posts: 105
Registered: ‎09-10-2012
Message 1 of 10 (1,285 Views)
Accepted Solution

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

1285 Views, 9 Replies
11-06-2012 05:33 AM

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 2013
Windows 7 Enterprise, 64-bit
Employee
Yijiang.Cai
Posts: 357
Registered: ‎05-20-2008
Message 2 of 10 (1,249 Views)

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

11-06-2012 07:40 PM 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.
Distinguished Contributor
waynehelley
Posts: 105
Registered: ‎09-10-2012
Message 3 of 10 (1,211 Views)

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

11-08-2012 12:54 AM 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 2013
Windows 7 Enterprise, 64-bit
Distinguished Contributor
waynehelley
Posts: 105
Registered: ‎09-10-2012
Message 4 of 10 (1,212 Views)

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

11-08-2012 01:22 AM 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 2013
Windows 7 Enterprise, 64-bit
Employee
Yijiang.Cai
Posts: 357
Registered: ‎05-20-2008
Message 5 of 10 (1,205 Views)

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

11-08-2012 01:30 AM 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.
Distinguished Contributor
waynehelley
Posts: 105
Registered: ‎09-10-2012
Message 6 of 10 (1,199 Views)

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

11-08-2012 01:32 AM 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 2013
Windows 7 Enterprise, 64-bit
Distinguished Contributor
waynehelley
Posts: 105
Registered: ‎09-10-2012
Message 7 of 10 (1,198 Views)

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

11-08-2012 01:35 AM 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 2013
Windows 7 Enterprise, 64-bit
Distinguished Contributor
waynehelley
Posts: 105
Registered: ‎09-10-2012
Message 8 of 10 (1,196 Views)

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

11-08-2012 01:36 AM in reply to: Yijiang.Cai

Thanks again for your help.

 

Much appreciated

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2013
Windows 7 Enterprise, 64-bit
Distinguished Contributor
waynehelley
Posts: 105
Registered: ‎09-10-2012
Message 9 of 10 (1,182 Views)

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

11-08-2012 02:27 AM 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 2013
Windows 7 Enterprise, 64-bit
Distinguished Contributor
waynehelley
Posts: 105
Registered: ‎09-10-2012
Message 10 of 10 (1,170 Views)

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

11-08-2012 04:04 AM 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 2013
Windows 7 Enterprise, 64-bit

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube