How can I know that this curve belongs to Assembly1?

How can I know that this curve belongs to Assembly1?

mohandis2
Advocate Advocate
277 Views
3 Replies
Message 1 of 4

How can I know that this curve belongs to Assembly1?

mohandis2
Advocate
Advocate
How can I know that this curve belongs to Assembly1?
Please see my code and screenshot.
Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Sheet = oDDoc.ActiveSheet
oView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select View")
Dim oDC As DrawingCurve
Dim oDCS As DrawingCurveSegment
For Each oDC In oView.DrawingCurves
	For Each oDCS In oDC.Segments
		
		'How can I know that this curve belongs to Assembly1?
		
	Next
Next

 

mohandis2_4-1716401458687.png

 

 

 

0 Likes
278 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @mohandis2.  This may be a more complicated endeavor than you may have had in mind.

You can use the following property of the DrawingCurve object:

DrawingCurve.ModelGeometry 

But that just returns a generic Object type, so you then have to test what type of object it retrieved from the model.  This is often just an Edge (if from a part) or an EdgeProxy (if from an assembly), but not always.  There are multiple types of things in the model that can be included in a DrawingView.  (Sketch related stuff, work features, etc.)

If it is an EdgeProxy, for example, then we can use its EdgeProxy.ContainingOccurrence property to get the assembly ComponentOccurrence object that it belongs to.  Then we can check ComponentOccurrence.ContextDefinition to get the ComponentDefinition object that it is in the 'context' of.  Then we can use the ComponentDefinition.Document property to get to the owning Document object.

 

However, there is still one big variable involved here that may be easy to overlook.  From the looks of it, you are showing the contents of one drawing view in your image above.  If so, then the view is directly referencing an assembly, not just a single multi-body part.  And if so, it looks like you may have two top level part type components, and one top level assembly type component in that main assembly.  The issue with this situation, is how to know when we have dug deep enough to figure out which document context you want to know about.  First level context would be the main assembly itself, not one of the components.  Next level context would be either one of the parts, or the one assembly within the main assembly.  But if it is part of an assembly, both the top level object will be a 'proxy', and the second level object will still be a 'proxy', but then, if you keep digging, you will eventually come to the native object that is not a proxy.  How to know where to stop digging it the issue here.

 

Edit:  One additional way to look at this is...that drawing line belongs to an edge within one of the parts, that is within 'Assembly1' ; and it also belongs to 'Assembly1', because there is a proxy of it in that assembly ; and it also belongs to 'Assembly2', because there is a proxy of it within that assembly also.  So, it can potentially belong to 3 different documents in that view, but you want to know about one in the middle.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

mohandis2
Advocate
Advocate

This looks really complicated, Let me explain my iLogic goal 

A- Select Assembly1 in the Model browser

B- Run an iLogic

C- The iLogic Selects Assembly1 curves in all active sheet views and changes Color or Layer 

Is the more simple to do than my old idea?

 

Thanks

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Hi @mohandis2.  Yes, that does sound simpler to achieve, but may still require quite a bit of processing behind the scenes, so the code may take a noticeable amount of time to do the task.  If simply changing all that geometry to another layer is acceptable, then that would definitely be the most efficient way to go, for multiple reasons.  When going that route, we can just gather all the DrawingCurveSegment objects on that one sheet into an ObjectCollection, then change them all to a specific layer at one time, instead of trying to make changes to each individual one, one at a time.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes