Insert 1 Document Into Another Document - A part into an assembly drawing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hollertrek
    New Member
    • Nov 2008
    • 11

    Insert 1 Document Into Another Document - A part into an assembly drawing

    I know this code references Autodesk Inventor (CAD) API, but I'm hoping for a generic solution to my problem with the following error. The error is "object reference not set to an instance of an object" and the macro takes an open document (part file drawing) and inserts it into another open document (assembly file).

    Code:
    Code:
            ' Set a reference to the assembly component definintion.
            ' This assumes an assembly document is open.
            Dim oAsmCompDef As AssemblyComponentDefinition
            oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
    
            ' Set a reference to the transient geometry object.
            Dim oTG As TransientGeometry
            oTG = ThisApplication.TransientGeometry
    
            ' Create a matrix. A new matrix is initialized with an identity matrix.
            Dim oMatrix As Matrix
            oMatrix = oTG.CreateMatrix
    
            ' Add the occurrence.
            Dim oOcc As ComponentOccurrence
            oOcc = oAsmCompDef.Occurrences.Add(sFileName, oMatrix)
    Hopefully this is not too specialized to receive help in this forum.

    Thx,
    Jon
  • hollertrek
    New Member
    • Nov 2008
    • 11

    #2
    Ok, let me simplify my explanation of what's going on. I get "Object variable or With block variable not set" when trying to execute the following that refers to the active document. I’ve also gotten the error, which is related, “object reference not set to an instance of an object.”

    Dim oAsmCompDef As Inventor.Assemb lyComponentDefi nition
    oAsmCompDef = ThisApplication .ActiveDocument .ComponentDefin ition

    Any idea why this would be happening?

    Jon

    Comment

    Working...