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

    Autodesk Inventor Customization

    Reply
    Distinguished Contributor
    Posts: 119
    Registered: ‎04-13-2005

    Substitute part for custom LOD

    200 Views, 10 Replies
    10-17-2009 07:55 AM
    The question to Inventor API experts.
    Inventor 2009 SP2

    Let’s assume we have an assembly model
    with two custom LODs named “State1” and “State2” and
    we have to create programmatically two substitute parts
    for each of custom LOD (as it is possible in UI from a dialog).

    I tried to modify DerivedAssemblyDefinition but failed.

    From on-line Help for DerivedAssemblyComponents:
    {code}
    Public Function CreateDefinition( _
    ByVal FullDocumentName As String _
    ) As DerivedAssemblyDefinition

    Parameters
    FullDocumentName
    String that specifies the full document name
    of the assembly document to create the definition for.
    If ONLY the FullFileName is specified, the master
    document within the assembly file is opened.
    {code}
    This is a very strange comment because method
    has only one parameter (filename).
    In which way I can specify NOT ONLY FullFileName
    (e.g. custom LOD)?

    I failed to change read/write property
    ActiveLevelOfDetailRepresentation of the just created
    DerivedAssemblyDefinition object.

    May be the only way to create DerivedAssemblyDefinition
    for a custom LOD is using of the property
    InclusionOption = kDerivedExcludeAll in conjunction
    with kDerivedIndividualDefined to add unsuppressed
    occurrences one by one?

    What is the recommended solution?
    Any help will be appreciated.

    -------------------------
    Here is my test sub.
    {code}
    Sub CreateSubstitutePart()

    Dim AssyFilename As String '' source assy file name
    AssyFilename = "C:\Temp\TestAssy.iam"

    Dim PartFileName As String '' file name for substitute part
    PartFileName = "C:\Temp\TestAssy_State1.ipt"

    ' create new part document (hidden mode)
    Dim oPartDoc As PartDocument
    oPartDoc = ThisApplication.Documents.Add( _
    DocumentTypeEnum.kPartDocumentObject, _
    ThisApplication.FileManager.GetTemplateFile( _
    DocumentTypeEnum.kPartDocumentObject), _
    False)

    Dim oPartCompDef As PartComponentDefinition
    oPartCompDef = oPartDoc.ComponentDefinition

    ' Create Derived Assembly Definition for the file AssyFilename
    Dim oDerivedAssyDef As DerivedAssemblyDefinition
    oDerivedAssyDef = oPartCompDef.ReferenceComponents. _
    DerivedAssemblyComponents.CreateDefinition(AssyFilename)

    ~~~~ OPTIONS ~~~~
    'Scale factor
    oDerivedAssyDef.ScaleFactor = 1
    'RMM flag
    oDerivedAssyDef.ReducedMemoryMode = True
    'Include all available components
    oDerivedAssyDef.InclusionOption = _
    DerivedComponentOptionEnum.kDerivedIncludeAll

    '------ this doesn’t work ----------
    'define nedded LOD - here is error message
    oDerivedAssyDef.ActiveLevelOfDetailRepresentation = "State1"
    '-----------------------------------

    'create derived component
    Call oPartCompDef.ReferenceComponents. _
    DerivedAssemblyComponents.Add(oDerivedAssyDef)
    oPartDoc.IsSubstitutePart = True ''substitute flag

    Call oPartDoc.SaveAs(PartFileName, False)
    Call oPartDoc.Close()

    End Sub
    {code}
    Please use plain text.
    *Sanjay Ramaswamy \(Autodesk\)

    Re: Substitute part for custom LOD

    10-19-2009 06:23 PM in reply to: ALink
    A FullDocumentName includes the name of the LOD as a suffix to the full file
    name. So if a file with a particular LOD is to be specified, the
    FullDocumentName should be used. If just the full file name is specified,
    the Master rep is assumed. See the modified sample below that obtains the
    full document name corresponding to the "State1" LOD and uses that to create
    the derived component.

    Also, you can set the ActiveLevelOfDetailRepresentation property, if you
    specify just the full file name. Not sure why that didn't work for you.
    Perhaps you got the name wrong (extra space in the name, etc.)?

    Sanjay-


    Sub CreateSubstitutePart()

    Dim AssyFilename As String '' source assy file name
    AssyFilename = "C:\Temp\TestAssy.iam"

    Dim PartFileName As String '' file name for substitute part
    PartFileName = "C:\Temp\TestAssy_State1.ipt"

    ' create new part document (hidden mode)
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.Documents.Add( _
    DocumentTypeEnum.kPartDocumentObject, _
    ThisApplication.FileManager.GetTemplateFile( _
    DocumentTypeEnum.kPartDocumentObject), _
    False)

    Dim oPartCompDef As PartComponentDefinition
    Set oPartCompDef = oPartDoc.ComponentDefinition

    Dim AssyDocumentName As String
    AssyDocumentName =
    ThisApplication.FileManager.GetFullDocumentName(AssyFilename, "State1")

    ' Create Derived Assembly Definition for the file AssyFilename
    Dim oDerivedAssyDef As DerivedAssemblyDefinition
    Set oDerivedAssyDef = oPartCompDef.ReferenceComponents. _
    DerivedAssemblyComponents.CreateDefinition(AssyDocumentName)

    ' ~~~~ OPTIONS ~~~~
    'Scale factor
    oDerivedAssyDef.ScaleFactor = 1
    'RMM flag
    oDerivedAssyDef.ReducedMemoryMode = True
    'Include all available components
    'oDerivedAssyDef.InclusionOption = _
    DerivedComponentOptionEnum.kDerivedIncludeAll

    '------ this doesn't work ----------
    'define nedded LOD - here is error message
    'oDerivedAssyDef.ActiveLevelOfDetailRepresentation = "State1"
    '-----------------------------------

    'create derived component
    Call oPartCompDef.ReferenceComponents. _
    DerivedAssemblyComponents.Add(oDerivedAssyDef)

    oPartDoc.IsSubstitutePart = True ''substitute flag

    Call oPartDoc.SaveAs(PartFileName, False)
    Call oPartDoc.Close

    End Sub
    Please use plain text.
    Distinguished Contributor
    Posts: 119
    Registered: ‎04-13-2005

    Re: Substitute part for custom LOD

    10-20-2009 05:00 AM in reply to: ALink
    Sanjay,
    thank you very much!

    That’s exactly what I need.
    FullDocumentName which includes the name of the LOD works fine.
    Nevertheless I failed to change value of the property
    ActiveLevelOfDetailRepresentation of new
    DerivedAssemblyDefinition object just created for Master LOD.

    Will you please modify the above Sub to illustrate
    ActiveLevelOfDetailRepresentation property use?

    ALink
    Please use plain text.
    *Sanjay Ramaswamy \(Autodesk\)

    Re: Substitute part for custom LOD

    10-20-2009 11:43 AM in reply to: ALink
    Here you go. This worked for me.

    Sanjay-


    Sub CreateSubstitutePart()

    Dim AssyFilename As String '' source assy file name
    AssyFilename = "C:\Temp\TestAssy.iam"

    Dim PartFileName As String '' file name for substitute part
    PartFileName = "C:\Temp\TestAssy_State1.ipt"

    ' create new part document (hidden mode)
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.Documents.Add( _
    DocumentTypeEnum.kPartDocumentObject, _
    ThisApplication.FileManager.GetTemplateFile( _
    DocumentTypeEnum.kPartDocumentObject), _
    False)

    Dim oPartCompDef As PartComponentDefinition
    Set oPartCompDef = oPartDoc.ComponentDefinition

    ' Create Derived Assembly Definition for the file AssyFilename
    Dim oDerivedAssyDef As DerivedAssemblyDefinition
    Set oDerivedAssyDef = oPartCompDef.ReferenceComponents. _
    DerivedAssemblyComponents.CreateDefinition(AssyFilename)

    ' ~~~~ OPTIONS ~~~~
    'Scale factor
    oDerivedAssyDef.ScaleFactor = 1
    'RMM flag
    oDerivedAssyDef.ReducedMemoryMode = True
    'Include all available components
    'oDerivedAssyDef.InclusionOption = _
    DerivedComponentOptionEnum.kDerivedIncludeAll

    '------ this doesn't work ----------
    'define nedded LOD - here is error message
    oDerivedAssyDef.ActiveLevelOfDetailRepresentation = "State1"
    '-----------------------------------

    'create derived component
    Call oPartCompDef.ReferenceComponents. _
    DerivedAssemblyComponents.Add(oDerivedAssyDef)

    oPartDoc.IsSubstitutePart = True ''substitute flag

    Call oPartDoc.SaveAs(PartFileName, False)
    Call oPartDoc.Close

    End Sub
    Please use plain text.
    Distinguished Contributor
    Posts: 119
    Registered: ‎04-13-2005

    Re: Substitute part for custom LOD

    11-11-2009 02:46 PM in reply to: ALink
    Sanjay,
    Thank you for your help.
    Will you please answer one more related question.

    The components of the assembly in CustomLOD
    may change their suppression status.
    Substitute part must reflect these changes.

    What is the recommended way for Release 2009, SP2
    to update existing substitute part which was created
    for assembly in CustomLOD in its previous state?

    “Assembly Tools” command “Update All Subtitutes”
    (and its code) doesn’t solve this problem.

    I tried several variants but failed.
    Sure it is possible to replace an old substitute part with
    an absolutely new one created for the current assembly state.

    But may be you know a way to modify an existing substitute part?
    Please use plain text.
    *Sanjay Ramaswamy \(Autodesk\)

    Re: Substitute part for custom LOD

    11-13-2009 11:38 AM in reply to: ALink
    If the substitute part was created by appropriately specifying the custom
    LOD ( using the the ActiveLevelOfDetailRepresentation property), this should
    be taken care of automatically. When the LOD is updated, the substitute part
    will be as well. This is not what you are seeing?

    Sanjay-
    Please use plain text.
    Distinguished Contributor
    Posts: 119
    Registered: ‎04-13-2005

    Re: Substitute part for custom LOD

    11-14-2009 11:31 AM in reply to: ALink
    Don’t know why but I still cannot change
    ActiveLevelOfDetailRepresentation property.
    Fortunately I can create DerivedAssemblyDefinition
    for custom LOD specifying FullDOcumentName.
    So this problem is solved.

    There is more interesting problem -

    If I create the substitute part specifying
    the custom LOD =AFTER= some components
    were suppressed, then DerivedAssemblyDefinition
    doesn’t “see” these suppressed components.

    So if these components are unsuppressed
    after substitute part creation
    automatic update of substitute part cannot
    visualize them – definition object knows
    nothing about them.

    So to have full control on the substitute part
    for the assembly with fixed number of known elements
    I need to make several steps;

    1. Activate custom LOD
    2. Unsuppress ALL components ( same as for Master)
    3. Create the substitute part with all components active.
    4. Suppress unnecessary components in custom LOD.
    5. Update the substitute part
    6. Link substitute part to the main assembly.

    From this moment I can use automatic update functionality in normal way.

    But what if some =NEW= components were added
    to subassembly AFTER step 6 completion and we have
    to modify existing substitute part?

    Can you post a sample code which can modify
    the DerivedAssemblyDefinition object of the existing
    substitute part “on the fly” to include absolutely
    new components?
    I made several attempts (in R2009 SP2), but failed.
    Is it possible with API?

    Or we have to create absolutely new substitute part
    to replace the old one?

    Thanks in advance.
    Please use plain text.
    *Sanjay Ramaswamy \(Autodesk\)

    Re: Substitute part for custom LOD

    11-16-2009 11:45 AM in reply to: ALink
    What I would recommend is for you to attempt your workflow thru the UI,
    rather than trying it thru the API first. If you can get things working in
    the UI, you can look into automating it next. If the UI doesn't work as
    you'd expect it to, you should post to the main Inventor newsgroup to get
    some ideas.

    Sanjay-
    Please use plain text.
    Valued Mentor
    Ktelang
    Posts: 268
    Registered: ‎09-23-2010

    Re: Substitute part for custom LOD

    08-30-2012 11:45 AM in reply to: *Sanjay Ramaswamy \(Autodesk\)

    I would like to bring this discussion to surface again.

    I am trying similar workflow with iAssemblies.

     

    In Inventor 2013

    Manually : I do a rightclick on level of Details and New Substitute > Derived Assembly

    That adds the substitute and creates it as I go. I have to again manually Suppress/Exclude

    from Derived assembly dialog box.

     

    I tried to automate this BUT

     

    {Code}

     

    Sub Cmd_Substitute_Assm()

    ' Open the factory document
    Dim oFacDoc As AssemblyDocument
    Set oFacDoc = ThisApplication.ActiveDocument

    Dim oCompdef As AssemblyComponentDefinition
    Set oCompdef = oFacDoc.ComponentDefinition

    Dim oiPrtFac As iAssemblyFactory
    Set oiPrtFac = oCompdef.iAssemblyFactory


    'Get filename to get foldername
    Dim Filename As String
    Filename = oFacDoc.FullDocumentName
    Debug.Print Filename

    Dim opath As String
    opath = Left(Filename, InStrRev(Filename, "\"))
    Debug.Print opath

    Dim oRow As iAssemblyTableRow
    Set oRow = oiPrtFac.DefaultRow

    Debug.Print oRow.MemberName

    Dim UnitNum As String
    UnitNum = oRow.MemberName

    Dim MasterLOD As LevelOfDetailRepresentation
    Set MasterLOD = oCompdef.RepresentationsManager.LevelOfDetailRepresentations.Item(1)

    Call MasterLOD.Activate


    1.'Add Subtitute : I think this only adds the existing substitute does not create one. , Correct ?


    Dim Subtitute  As LevelOfDetailRepresentation
    Set Subtitute = oCompdef.RepresentationsManager. _
    LevelOfDetailRepresentations.AddSubstitute(opath & "Substitutes\" & UnitNum & ".ipt", False)


    End Sub

    {Code}

     

    2.Is there a way by which I can replicate the steps as I do manually ?

     

    Hello Sanjay, In your previous post you had

     

    ' ~~~~ OPTIONS ~~~~
    'Scale factor
    oDerivedAssyDef.ScaleFactor = 1
    'RMM flag
    oDerivedAssyDef.ReducedMemoryMode = True
    'Include all available components ..................(from old code)

    3. 'In my case, I want to exclude the excluded components as per the iassembly definition.

    ' Can you please illustrate that ?
    'oDerivedAssyDef.InclusionOption =_
    'DerivedComponentOptionEnum.kDerivedIncludeAll

     

    ------------------------------------------------------------------------------
    Config :: Intel (R) Xeon (R) CPU E31245 @ 3.30 GHz, 16.0 GB, 64bit win7
    Inventor 2013 and Vault Basic 2013
    -----------------------------------------------------------------------------
    Please use plain text.
    Valued Mentor
    Ktelang
    Posts: 268
    Registered: ‎09-23-2010

    Re: Substitute part for custom LOD

    08-30-2012 11:49 AM in reply to: Ktelang

    Precisely: I am trying to create a Substitute LOD for each member in iassembly.

    So that the overall assembly will be easier.

     

    Thanks

    ------------------------------------------------------------------------------
    Config :: Intel (R) Xeon (R) CPU E31245 @ 3.30 GHz, 16.0 GB, 64bit win7
    Inventor 2013 and Vault Basic 2013
    -----------------------------------------------------------------------------
    Please use plain text.