acces feature properties from an feature in drawing environment

acces feature properties from an feature in drawing environment

robbeRtek
Advocate Advocate
685 Views
9 Replies
Message 1 of 10

acces feature properties from an feature in drawing environment

robbeRtek
Advocate
Advocate

Hi,

Can someone tell me how to access the 'feature properties' from an feature select in an drawing view in the drawing environment through ilogic?
or otherwise --> we want to change each curve/edge that's created from an 'surface body feature'  in 'dashed' instead of 'by layer'

Thanks alot

robbeRtek_0-1705505932173.pngrobbeRtek_1-1705506026963.png

 



0 Likes
Accepted solutions (1)
686 Views
9 Replies
Replies (9)
Message 2 of 10

WCrihfield
Mentor
Mentor

Hi @robbeRtek.  The code required to accomplish what you are asking for is pretty long and complicated.  And would get even more long and complicated if the view was referencing an assembly, instead of a part.  It is far easier to do manually than by code.  The process would also change a lot depending on how you want to specify which feature to target.  If you are planning on selecting the model browser node of that feature in the model tree, then it would need to include a bunch of code for navigating that model browser tree and its associated objects, to get a reference to the actual feature object, and to determine which drawing view to target.  If initially selecting an individual line/curve on the sheet, within the view geometry itself, then we would need to dig down several layers to find what actual Edge (or multiple other possible types of object) within the model that selected line/curve is associated with, then climb up through its 'parent' objects within the model to find which body/feature it belongs to.  Then, if/when the feature is found, we need to get all the other geometry within the drawing view that belongs to the same feature.  Then we either need to change what layer all that geometry is on all at once, or iterate through each individual piece of view geometry, and change property values for them.  The task that was done by code is not nearly as simple, or easy to change back to the way it was later if needed either.  There is a way to bundle multiple actions into one entry within the UNDO list, but that will only work if you use that immediately after the rule has finished, and before you do anything else.  We do not have access to control anything within that specific little dialog by code either.  That is just a convenient little user interface dialog, to make the manual process simpler.

 

But there are multiple similar examples of code for tasks similar to this one here on the forum.  Those other similar example codes would likely all need to be customized to your specific needs though, because everyone wants to do things a little differently.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 10

FINET_Laurent
Advisor
Advisor

Hi @robbeRtek,

 

For this kind of task I would probably loop through all the curves inside the specified views & check from what (inside the 3Dmodel) it has been created (feature) with the .CreatedByFeature . Here is an example : 

Dim doc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
Dim s As Inventor.Sheet = doc.ActiveSheet
Dim v As Inventor.DrawingView = s.DrawingViews.Item(1)

For Each c As Inventor.DrawingCurve In v.DrawingCurves
	If c.ModelGeometry.Type <> ObjectTypeEnum.kEdgeObject Then Continue For
		
	Dim e As Inventor.Edge = c.ModelGeometry
	If e.Faces.Count = 0 Then Continue For
			
	For Each f As Inventor.Face In e.Faces
		If f.CreatedByFeature.Name = "Ouverture1" Then 
			c.LineType = LineTypeEnum.kDashedLineType
			c.LineWeight = 0.1
			Exit For
			
		End If		
	Next
Next

 

FINET_Laurent_1-1705563839406.png

Does this suits your needs?

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 4 of 10

robbeRtek
Advocate
Advocate

Hello,

@WCrihfield  Thanks for reply, for the feature props i was already thinking to the model browser nodes, but it's to complex, so as you say.
@FINET_Laurent  thanks for the snippet, i had already something like that but with a small mistake to actual change the style,
But use the

CreatedByFeature.type or CreatedByFeature.name

 is not use full, i want to change all edges created from an surface bodie, not an solid,
it can be, that we use 'thicken' , sweep, extrude, ... (in surface mode)
So i found an way to do :
the code can run 30 sheets, with 6 vieuws/sheet that need to be changed in 2min on mine workstation, but there is a small bug,...
The last vieuw is not change... maybe you know why?
i can force hardcore to do the last vieuw again but it is not the way to do,...
here is mine code :

Dim doc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
Dim SheetList As Inventor.Sheets = doc.Sheets
Dim s As Inventor.Sheet '= doc.ActiveSheet
Dim viewList As Inventor.DrawingViews '= s.DrawingViews
Dim v As Inventor.DrawingView
Dim CurvelistSurface As New List(Of Inventor.DrawingCurve)
Dim blfound As Boolean = False
For Each s In SheetList
	If s.DrawingViews.Count = 0 Or _
		Not TypeOf s.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument _
		Is Inventor.PartDocument Then Continue For
	s.Activate
	viewList = s.DrawingViews
	For Each v In viewList
		'If Not (v.IncludeSurfaceBodies = True AndAlso v.DesignViewRepresentation = "MetLakzijde") Then Continue For
		If Not v.IncludeSurfaceBodies = True Then Continue For
		Dim CurvelistOriginal As New List(Of Inventor.DrawingCurve)
		For Each c In v.DrawingCurves
			CurvelistOriginal.Add(c)
		Next
		v.IncludeSurfaceBodies = False
		s.Update
		Dim CurvelistModel As New List(Of Inventor.DrawingCurve)
		For Each c In v.DrawingCurves
			CurvelistModel.Add(c)
		Next
		v.IncludeSurfaceBodies = True
		s.Update
		For Each obj As Object In CurvelistOriginal
			blfound = False
			For Each obj2 As Object In CurvelistModel
				If obj Is obj2 Then
					blfound = True
					Exit For
				End If
			Next
			If blfound = False Then
				CurvelistSurface.Add(obj)
			End If
		Next
	Next

	For Each c In CurvelistSurface
		c.LineType = LineTypeEnum.kDashedHiddenLineType 'kDashedLineType=dashed space
		'c.LineWeight = 0.02
	Next
	s.Update
Next




0 Likes
Message 5 of 10

FINET_Laurent
Advisor
Advisor

@robbeRtek,

 

Then you only need to switch the .CreatedByFeature method to the .SurfaceBody method (line 12). See example :

Dim doc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
Dim s As Inventor.Sheet = doc.ActiveSheet
Dim v As Inventor.DrawingView = s.DrawingViews.Item(1)

For Each c As Inventor.DrawingCurve In v.DrawingCurves
	If c.ModelGeometry.Type <> ObjectTypeEnum.kEdgeObject Then Continue For
		
	Dim e As Inventor.Edge = c.ModelGeometry
	If e.Faces.Count = 0 Then Continue For
			
	For Each f As Inventor.Face In e.Faces
		If f.SurfaceBody.Name = "Srf1" Then 
			c.LineType = LineTypeEnum.kDashedLineType
			c.LineWeight = 0.1
			Exit For
			
		End If		
	Next
Next

I guess it would be faster than creating many collections..

FINET_Laurent_1-1705583236251.png

 

As for your code I don't realy know. Can you provide us the files so we can test ?

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 6 of 10

robbeRtek
Advocate
Advocate
Accepted solution

Hi

@FINET_Laurent  thanks for your support :
the original code don't work for this case :

robbeRtek_0-1705586141318.png

An other thing is name 'sfr1'...
Here is the full code, it change 180vieuw/30sheets in +/-20sec what's a higher performence.
thanks alot.

Dim doc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
Dim SheetList As Inventor.Sheets = doc.Sheets
Dim s As Inventor.Sheet '= doc.ActiveSheet
Dim viewList As Inventor.DrawingViews '= s.DrawingViews
Dim v As Inventor.DrawingView
Dim f As Inventor.Face
Dim c As Inventor.DrawingCurve
Dim e As Inventor.Edge
For Each s In SheetList
	If s.DrawingViews.Count = 0 OrElse _
	Not TypeOf s.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument _
	Is Inventor.PartDocument Then Continue For
	viewList = s.DrawingViews
	For Each v In viewList
		For Each c In v.DrawingCurves
			If c.ModelGeometry.Type = ObjectTypeEnum.kEdgeObject Then 'Continue For
				 e= c.ModelGeometry
				If e.Faces.Count = 0 Then Continue For
				For Each f In e.Faces
					If f.SurfaceBody.IsSolid = False Then
						c.LineType = LineTypeEnum.kDashedHiddenLineType 'kDashedLineType=dashed space
						'c.LineWeight = 0.1
						Exit For
					End If
				Next
			ElseIf c.ModelGeometry.Type = ObjectTypeEnum.kFaceObject Then
				f = c.ModelGeometry
				If f.SurfaceBody.IsSolid = False Then
					c.LineType = LineTypeEnum.kDashedHiddenLineType 'kDashedLineType=dashed space
					'c.LineWeight = 0.1
				End If
			End If
		Next
	Next
	Next
	doc.Update
0 Likes
Message 7 of 10

WCrihfield
Mentor
Mentor

Hi guys.  The section line in that view will be a SketchLine Type object.  I noticed recently that adding a section line to a view for defining a section view makes that view's DrawingCurves collection get two more objects in it, and both of them are SketchLine Type objects.  When you delete that section line, those two objects go away from the DrawingCurves collection.  The topic came up do to someone adding automated overall dimensions to their drawing views, and that line getting dimensioned, instead of the outer most geometry of the view itself.

Edit:  Also, if you are using the CommandManager.Pick function, and using the DrawingCurveSegments filter, if you click that section line, it will still be a SketchLine, instead of a normal DrawingCurveSegment, which can cause errors if you pre-defined the variable as a DrawingCurveSegment.

 

Edit 2:  I should clarify that this apparently became an issue with the 2024.2 update, and here is a link to another recent forum response pointing this out.

https://forums.autodesk.com/t5/inventor-programming-ilogic/error-unable-to-cast-com-object-of-type-s... 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 10

FINET_Laurent
Advisor
Advisor

@WCrihfield,

 

Thank you for this clarification. This explains few misterious error messages.. 🙂 

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 9 of 10

WCrihfield
Mentor
Mentor

Hi @robbeRtek.  If you are worried about performance, then there are several other tricks you can take advantage of.  There is also a different way to accomplish the outcome you are looking for, which could likely require less processing.  Changing the property values of every single DrawingCurve object individually takes a lot of processing.  But instead you could gather all DrawingCurves for that feature on an entire sheet into one ObjectCollection, then use the Sheet.ChangeLayer method to change them all to a specific layer instantly.  That layer can be one you have prepared ahead of time with those property values, or you can have the code find/create it, then use it that way.  That one is a process change, but there are other tricks too, like turning off screen updating while the code is running, then turning it back on at the end, and others.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 10

robbeRtek
Advocate
Advocate

Thanks! First, create working code, and then scale up the performance. 😉 Here is the full code; it changes 180 views/30 sheets in 5-6 seconds (written in iLogic). I believe if I add it to our app (VB.NET), the performance will be much better.

Sub main
Dim _inv As Inventor.Application = ThisApplication
_inv.ScreenUpdating= False
Dim doc As Inventor.DrawingDocument = _inv.ActiveDocument
Dim TM As TransactionManager = _inv.TransactionManager
Dim Trans As Transaction = TM.StartTransaction(doc, "change Layer Paint")
On Error GoTo ErrorHandler
Dim SheetList As Inventor.Sheets = doc.Sheets
Dim s As Inventor.Sheet 
Dim viewList As Inventor.DrawingViews 
Dim v As Inventor.DrawingView
Dim f As Inventor.Face
Dim c As Inventor.DrawingCurve
Dim e As Inventor.Edge
Dim col As ObjectCollection
Dim seg As DrawingCurveSegment
col=_inv.TransientObjects.CreateObjectCollection
Dim lay As Layer = SearchOrCreateLayer(doc,"Paint")
If lay Is Nothing Then 
	MsgBox("No layer named :'Paint', it's faild to create")
	GoTo ErrorHandler
End If 
For Each s In SheetList
	If s.DrawingViews.Count = 0 OrElse _
	Not TypeOf s.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument _
	Is Inventor.PartDocument Then Continue For
	viewList = s.DrawingViews
	For Each v In viewList
		If  Not v.IncludeSurfaceBodies = True Then Continue For
		For Each c In v.DrawingCurves
			If c.ModelGeometry.Type = ObjectTypeEnum.kEdgeObject Then 'Continue For
				 e= c.ModelGeometry
				If e.Faces.Count = 0 Then Continue For
				For Each f In e.Faces
					If f.SurfaceBody.IsSolid = False Then
						'c.LineType = LineTypeEnum.kDashedLineType 'kDashedLineType=dashed space
						'c.LineWeight = 0.1
						For Each seg In c.Segments
						col.Add(seg)
						Next
						Exit For
					End If
				Next
			ElseIf c.ModelGeometry.Type = ObjectTypeEnum.kFaceObject Then
				f = c.ModelGeometry
				If f.SurfaceBody.IsSolid = False Then
					'c.LineType = LineTypeEnum.kDashedLineType'kDashedHiddenLineType 'kDashedLineType=dashed space
					'c.LineWeight = 0.1
					For Each seg In c.Segments
						col.Add(seg)
						Next
				End If
			End If
		Next
		Next
If col.Count> 0 Then		
s.ChangeLayer(col, lay)
col.Clear
End If
Next
Trans.End
_inv.ScreenUpdating= True
doc.Update
		Exit Sub
ErrorHandler :
Trans.Abort
_inv.ScreenUpdating= True
End Sub
	
Function SearchOrCreateLayer(doc As DrawingDocument, name As String)As Layer
Dim lays As LayersEnumerator = doc.StylesManager.Layers
 Dim existingLayer As Layer = Nothing
Try
 existingLayer = lays.Item(name)
 Catch
 End Try
If Not existingLayer Is Nothing Then
        Return existingLayer
 End If
Dim NewLayer As Layer = lays.Item("Visible (ISO)").Copy(name)
'        ' change color 
'        Dim oColor As Color
'        oColor = oNewLayer.Color
'        oColor.Red = 255
'        oColor.Green = 0
'        oColor.Blue = 0
'        oNewLayer.Color = oColor
NewLayer.LineType = LineTypeEnum.kDashedHiddenLineType
'NewLayer.LineWeight=0.01
Return NewLayer
	End Function

The only thing is the try-catch;

without it, it fails. If you see other things to do for higher performance and robust code, ...

thanks a lot

0 Likes