Accessing a sketch from an Assembly

Accessing a sketch from an Assembly

Anonymous
Not applicable
362 Views
2 Replies
Message 1 of 3

Accessing a sketch from an Assembly

Anonymous
Not applicable
Can someone give me the 'trail' that would allow me to access a sketch from an assembly. I am working with 3 parts in an assembly and have succesfully opened one for editing with "...ComponentOccurence.Edit" but have been unable to get to my sketch. Any pointers or examples would be greatly appreciated. Thanks in advance for any help.
0 Likes
363 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
You don't need to use the ComponentOccurrence.Edit
method to access information in the part.  The Edit method is used to put
the occurrence into edit mode within the user interface.  Using the API you
can access the part directly without putting it into edit mode.  The VBA
sample below illustrates accessing the contents of a part from with the
assembly.  It displays the name of each sketch within the part, changes the
value of a parameter within the part, and updates the part.  Hopefully this
is enough to get you started.

 

Public Sub
EditPart()
    Dim oDoc As
AssemblyDocument
    Set oDoc =
ThisApplication.ActiveDocument
   
    '
Get an occurrence in the assembly.
    ' For simplicity, this
just gets the first one.
    Dim oOcc As
ComponentOccurrence
    Set oOcc =
oDoc.ComponentDefinition.Occurrences.Item(1)
   

    ' Get the part's component
definition.
    Dim oPartDef As
PartComponentDefinition
    Set oPartDef =
oOcc.Definition
   
    ' You now have
access to the part information just the same
    ' as if you
had accessed the part directly.  The code below
    '
demonstrates accessing some of the part information.
    Dim
oSketch As Sketch
    Debug.Print
"Sketches"
    For Each oSketch In
oPartDef.Sketches
        Debug.Print
"  " & oSketch.Name
    Next
   

    ' Change the value of a parameter.
   
Dim oParam As Parameter
    Set oParam =
oPartDef.Parameters.Item("d0")
    oParam.Value = oParam.Value
* 2
   
    ' Update the
part.
    oPartDef.Document.Update
End Sub

--

Brian Ekins
Developer Technical Services, Autodesk
Discussion Q&A:

href="http://www.autodesk.com/discussion">http://www.autodesk.com/discussion



style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Can
someone give me the 'trail' that would allow me to access a sketch from an
assembly. I am working with 3 parts in an assembly and have succesfully opened
one for editing with "...ComponentOccurence.Edit" but have been unable to get
to my sketch. Any pointers or examples would be greatly appreciated. Thanks in
advance for any help.
0 Likes
Message 3 of 3

Anonymous
Not applicable
Thank you for your help.
0 Likes