How to know if a DrawingCurve is also a sketch entity?

How to know if a DrawingCurve is also a sketch entity?

J.Pelfrene
Enthusiast Enthusiast
267 Views
5 Replies
Message 1 of 6

How to know if a DrawingCurve is also a sketch entity?

J.Pelfrene
Enthusiast
Enthusiast

Hi,

 

For a post-processing action, I would need to extract information from drawing documents (.idw)

A DrawingView contains a collection of DrawingCurves and Sketches. In examining a document, I find that there is an overlap between the DrawingCurves and the SketchEntities (contained in a Sketch object). All curves that are SketchEntities are also in the DrawingCurves. But is there a way to know if a certain DrawingCurve originates from a Sketch?

 

Thank you.

0 Likes
Accepted solutions (1)
268 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Hi @J.Pelfrene.  When you say that you are finding sketch entities in the DrawingCurves, are you referring to sketch entities of a DrawingSketch, or entities of sketches in the model?  When we make sketches in a drawing, they can either belong to the Sheet, or to a DrawingView.  If you have a sketch in your drawing, and the view is its 'Parent', then that sketch's geometry will be found within the DrawingView.DrawingCurve collection.  And you can tell which ones they are using:

 

Logger.Info(TypeName(oDrawingCurve.ModelGeometry))

 

The 'model geometry' of most curves will usually be Edge or EdgeProxy, but can be several different types of things, which is why DrawingCurve.ModelGeometry returns Object type, instead of Edge or another specific type.  Another related property would be the DrawingCurve.EdgeType, but it does not have a variation for sketch entities, so not useful in this case.

Edit:  Since checking Log entries will not tell you 'which' ones you are looking for, and testing String type values is not that efficient, below is another example iLogic rule you can test with, which you may then be able to use some of it in your overall code based solution.  This will let you manually select a view with your mouse after you start the rule, then it will start iterating through its DrawingCurves, checking the Type of each curve's model geometry using 'TypeOf' operator, which is much more efficient.  When it finds ones that represent some sort of SketchEntity, it then gathers those up into two different collections.  One for the ones belonging to DrawingSketch belonging to that DrawingView, and one for model based sketch entities.  Then at the end, if any were found, it will highlight them, and prompt you to review them, only while that message dialog is showing, then they are cleared from the HighLightSet, and the other group is evaluated.  So, at the end, if you do not need to 'see' which ones are which, you can use one, or both of those collections however you may need later.

Dim oInvApp As Inventor.Application = ThisApplication
Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a Drawing View.")
If oView Is Nothing Then Exit Sub
Dim oSheet As Inventor.Sheet = oView.Parent
Dim oDDoc As DrawingDocument = oSheet.Parent
Dim oTO As TransientObjects = oInvApp.TransientObjects
Dim oOtherSketchCurves As Inventor.ObjectCollection = oTO.CreateObjectCollection()
Dim oViewSketchCurves As Inventor.ObjectCollection = oTO.CreateObjectCollection()
For Each oDC As DrawingCurve In oView.DrawingCurves
	Dim oMG As Object = oDC.ModelGeometry
	If TypeOf oMG Is SketchEntity Then
		Dim oSE As SketchEntity = oMG
		Dim oSketch As Inventor.Sketch = oSE.Parent
		If TypeOf oSketch Is DrawingSketch Then
			For Each oDCS As DrawingCurveSegment In oDC.Segments
				oViewSketchCurves.Add(oDCS)
			Next
		Else
			For Each oDCS As DrawingCurveSegment In oDC.Segments
				oOtherSketchCurves.Add(oDCS)
			Next
		End If
	End If
Next
Dim oHLS As HighlightSet = oDDoc.CreateHighlightSet()
If oViewSketchCurves.Count > 0 Then
	oHLS.AddMultipleItems(oViewSketchCurves)
	MsgBox("Review Highlighted DrawingCurves belonging to View Sketch.", , "")
	oHLS.Clear()
End If
If oOtherSketchCurves.Count > 0 Then
	oHLS.AddMultipleItems(oOtherSketchCurves)
	MsgBox("Review Highlighted DrawingCurves belonging to 'other' Sketches.", , "")
	oHLS.Clear()
End If

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

J.Pelfrene
Enthusiast
Enthusiast

Hi @WCrihfield,
Thank you for the code snippet!
It is indeed the sketches that belong to a drawing view that I'm after. In the collection of DrawingCurves are both the curves of the part view and the curves of an additional sketch. From the DrawingCurves collection I can't seem to query where each curve originates from.

 

I tried to request the 'ModelGeometry' information, but it consistenly throws an error. In a Try-Catch statement, none of the DrawingCurves return any value for the ModelGeometry.

 

I use the following to get some information on a drawing's contents:

 

Sub Main()
	If Not ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then
			MsgBox("You can run this command only from an open Drawing document")
			Exit Sub
		End If		
	
	oDrawDoc = ThisApplication.ActiveDocument
	oSheet = oDrawDoc.ActiveSheet
	
	ExploreModel()	
		
End Sub

Private Sub ExploreModel()	
	Dim strout As String = "" 
	
	strout &= "Num Doc Views: " & oDrawDoc.Views.Count & vbNewLine
	strout &= "Num Sketches: " & oSheet.Sketches.Count & vbNewLine
	
	strout &= vbNewLine & "SKETCHES" & vbNewLine
	
	Dim oSketch As DrawingSketch
	For Each oSketch In oSheet.Sketches
		strout &= "Sketch: " & oSketch.Name & vbNewLine
		strout &= "    Entities: " & oSketch.SketchEntities.Count & vbNewLine
	Next
	
	strout &= vbNewLine & "DRAWING VIEWS" & vbNewLine
	
	Dim oDrawingView As DrawingView
	For Each oDrawingView In oSheet.DrawingViews
		strout &= "View: " & oDrawingView.Name & vbNewLine
		strout &= "  Curves: " & oDrawingView.DrawingCurves.Count & vbNewLine
			
		Dim oCurve As DrawingCurve
		For Each oCurve In oDrawingView.DrawingCurves			
			Try
				Dim oMG As Object = oCurve.ModelGeometry
				strout &= "    " & TypeName(oCurve.ModelGeometry) & vbNewLine
			Catch
			End Try
		Next
		
		For Each oSketch In oDrawingView.Sketches
			strout &= "  Sketch: " & oSketch.Name & vbNewLine
			strout &= "    Entities: " & oSketch.SketchEntities.Count & vbNewLine
		Next
	Next	
	
	
	MsgBox(strout)
End Sub

Public oDrawDoc As DrawingDocument
Public oSheet As Sheet

 

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor

Hi @J.Pelfrene.  I quickly reviewed your code and did not really see anything that I would think was problematic or error prone.  I also copied that code you posted this morning directly over into a new internal iLogic rule within one of my drawings, then ran it.  I only had one DrawingView on my sheet (of an assembly model), and no DrawingSketches at all, but the rule ran OK for me, and the message dialog was too tall for my computer screen, and was full of a list of words like 'EdgeProxy' & 'FaceProxy', as expected.  So, that means that the 'ModelGeometry' was retrieved OK in my quick test.  I am currently using Inventor Pro 2024.3.3, but I don't know if version is important here.

 

The DrawingCurve.ModelGeometry property's online help documentation says:

"Property that returns the corresponding geometry from the model. This property returns Nothing in the case the model is not available."

So, it seems like it would just return 'Nothing' instead of throwing an error when accessing that property, and for some reason the model was not available.  Was one or more of your views a 'draft' view, or something odd like that?  It seems like draft views don't actually reference a model document, so that property would not work on those types of views.  Otherwise I don't know why you may be getting the errors.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

J.Pelfrene
Enthusiast
Enthusiast

Thank you. I see. For the .idw-files that I'm analysing I don't have access to the associated 3D geometry files. But then DrawingCurve.ModelGeometry should return Nothing according to the documentation. However, it does return an error in both Inventor 2023 and 2025 in my case, and for both the drawing curves that originate from a model view and those from a sketch.
In the meantime, I found that I can distinguish them from their Layer (for my set of .idw-files).
I also see that the Model Geometry information is the way to do it for an .idw where the associated 3D file is available, so I'll accept your solution.

Thank you for taking the time to look into this question!

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

Your welcome.  And thanks for that extra information about your specific situation.  Knowing that the views are referencing model files, but that you don't have access to those model files, is useful to know and helps explain this unexpected behavior.  If a view did not reference any model file, that would be one thing, but when it does reference a model file, but that model file can not be accessed, may be the difference between that property returning 'Nothing' and causing an error.  I will try to keep that in mind.  And now others will be able to read about it also, if they encounter a situation like this.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)