API to access DisplayName of the Component associated with a DrawingCurveSegment

API to access DisplayName of the Component associated with a DrawingCurveSegment

Anonymous
Not applicable
1,463 Views
4 Replies
Message 1 of 5

API to access DisplayName of the Component associated with a DrawingCurveSegment

Anonymous
Not applicable

Hi All,

 

I am trying to introduce some automation into a drawing document (.dwg) of an Assembly

 

The task to accomplish here is to get the displayName (or even Occurrence.Name) of the component, which is represented in the Drawing document by a drawingCurveSegment

A sample program to illustate what my goals would something like this;

 

 

Dim objDrawingDoc as DrawingDocument = ThisApplication.ActiveDocument

 

Dim objCurrentSheet as Sheet = objDrawingDoc.ActiveSheet

 

Dim objCurveSegment as DrawingCurveSegment

Set objCurveSegment = objCurrentSheet.SelectSet.Item(1)

 

msgBox "This component is :" & objCurveSegment.????? (something like ReferencedDocumentDescriptor)

 

I have given it a number of tries, but have not succeeded.

I found a complete sample code which is intended to do the same task in the Help documentation of Inventor (under Create Ballon), but the copied code has failed. (see attachment for error message)

 

I have also attahced a copy of the same code.

 

If anyone can give me an idea/clue for this task that would be awsome.

 

Thanking you.

Wajih

0 Likes
Accepted solutions (1)
1,464 Views
4 Replies
Replies (4)
Message 2 of 5

Vladimir.Ananyev
Alumni
Alumni
Accepted solution

If you need a reference to the component occurrence associated

with the selected drawing curve segment, try the following VBA sample. 

 

Private Sub Component_From_DrawingCurve()
  
  'create drawing view for assembly document,
  'select some drawing segment
  'and run this macro
  
  Dim oDoc As DrawingDocument
  Set oDoc = ThisApplication.ActiveDocument
  Dim oSheet As Sheet
  Set oSheet = oDoc.ActiveSheet

  ' Set a reference to the drawing curve segment.
  ' This assumes that a drwaing curve is selected.
  Dim oDrawingCurveSegment As DrawingCurveSegment
  Set oDrawingCurveSegment = oDoc.SelectSet.Item(1)

  ' Set a reference to the drawing curve.
  Dim oDrawingCurve As DrawingCurve
  Set oDrawingCurve = oDrawingCurveSegment.Parent
  
  ' Set a reference to the parent component occurrence
  Dim oOcc As ComponentOccurrence
  Set oOcc = oDrawingCurve.ModelGeometry.ContainingOccurrence

  Debug.Print oOcc.Name & "  is selected."
  
  Beep
  MsgBox oOcc.Name & "  is selected."

End Sub

 Cheers,

 


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 3 of 5

Anonymous
Not applicable

Thank you Vladimir,

 

It works brilliantly.

 

One more thing, how would I cycle through all the DrawingCurveSegments??

 

This approach is wrong and thus does not work;

 

Dim oDrawingCurves As DrawingCurvesEnumerator

 

Set oDrawingCurves = ThisApplication.ActiveDocument.AllReferencedDocuments

 

But, thank you again for the solution.

Wajih

 

0 Likes
Message 4 of 5

Anonymous
Not applicable

Oh,

 

Worked another way,

 

Dim oDrawingView As DrawingView

 

Set oDrawingView = ThisApplication.ActiveDocument.selectSet.item(1)

 

Dim intCurves As Integer

 

For intCurves = 1 to oDrawingView.DrawingCurves.Count

 

     Dim oCurve As DrawingCurve

 

    Set oCurve = oDrawingView.DrawingCurves.(intCurves)

 

Next

 

 

 

 

 

Wajih

 

0 Likes
Message 5 of 5

Vladimir.Ananyev
Alumni
Alumni

Hi Wajih,

Thanks for good news.

For Each - Next loop should work a bit faster (and less code)

 

Dim oCurve As DrawingCurve
For each oCurve in oDrawingView.DrawingCurves
   'do something with oCurve

Next

 Cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network