• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Autodesk Inventor

    Reply
    Valued Contributor
    Posts: 94
    Registered: ‎09-10-2012
    Accepted Solution

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

    555 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 2011
    Windows 7 Enterprise, 64-bit
    Please use plain text.
    Employee
    Posts: 283
    Registered: ‎05-20-2008

    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

    Quality Assurance Team
    Autodesk, Inc.
    Please use plain text.
    Valued Contributor
    Posts: 94
    Registered: ‎09-10-2012

    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 2011
    Windows 7 Enterprise, 64-bit
    Please use plain text.
    Valued Contributor
    Posts: 94
    Registered: ‎09-10-2012

    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 2011
    Windows 7 Enterprise, 64-bit
    Please use plain text.
    Employee
    Posts: 283
    Registered: ‎05-20-2008

    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

    Quality Assurance Team
    Autodesk, Inc.
    Please use plain text.
    Valued Contributor
    Posts: 94
    Registered: ‎09-10-2012

    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 2011
    Windows 7 Enterprise, 64-bit
    Please use plain text.
    Valued Contributor
    Posts: 94
    Registered: ‎09-10-2012

    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 2011
    Windows 7 Enterprise, 64-bit
    Please use plain text.
    Valued Contributor
    Posts: 94
    Registered: ‎09-10-2012

    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 2011
    Windows 7 Enterprise, 64-bit
    Please use plain text.
    Valued Contributor
    Posts: 94
    Registered: ‎09-10-2012

    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 2011
    Windows 7 Enterprise, 64-bit
    Please use plain text.
    Valued Contributor
    Posts: 94
    Registered: ‎09-10-2012

    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 2011
    Windows 7 Enterprise, 64-bit
    Please use plain text.