Custom Feature note on drawing to iFeature with parameters

Custom Feature note on drawing to iFeature with parameters

loicLPQZG
Contributor Contributor
625 Views
4 Replies
Message 1 of 5

Custom Feature note on drawing to iFeature with parameters

loicLPQZG
Contributor
Contributor

Hello all,

 

In short: I am trying to get a custom anotation in an assembly drawing which shows the ifeature name [Picture: black box] from within a part and a userparameter[Picture:red box] (the level)stored within the part that the ifeature is in.

 

So I want to be able to select a feature (or a DrawingCurveSegment) from within a section view and have an annotation leader attatched to the line which containts the name of the ifeature ( as show in the model browser A/B/C/D) aswell as the level of the feature which is stured inside the user parameters of the part that contains the ifeature.

 

What i have tried:

I am able to get the part name with 

oLine = ThisApplication.CommandManager.Pick(electionFilterEnum.kDrawingCurveSegmentFilter, "Select a line")
oLine.Parent.ModelGeometry.Parent.Parent

So i would be able to use this to find the user parameters.

If i remove 1 parent i only get the Solid and am not able to reach the feature.

 

I am struggeling to reach the name and the parameters of the ifeature, frow within the drawing.

The line below works from within the part but not from within the drawing.

 

 

oFeat = ThisApplication.CommandManager.Pick(electionFilterEnum.kPartFeatureFilter, "Select a Feature")

 

 

 

Any help or leads would greatly be apreciated!

Many thanks!

 

Edit: i am not able to share the files of this project but it is straigh forward and I would be able to provide a dummy file.

0 Likes
Accepted solutions (2)
626 Views
4 Replies
Replies (4)
Message 2 of 5

marcin_otręba
Advisor
Advisor
Accepted solution

hi,

 

you can start from this one:

 

Sub Main()
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oActiveSheet As Sheet = oDrawDoc.ActiveSheet
Dim oDrawingCurve As DrawingCurve= ThisApplication.CommandManager.Pick(kDrawingCurveSegmentFilter, "pick drawing curve").parent
Dim ed As Edge= oDrawingCurve.ModelGeometry
Dim oFace As Face
For Each oFace In ed.Faces
    Dim prtfeature As PartFeature = oFace.CreatedByFeature
    If prtfeature.Type = 83998208 Then
	Dim ifeat As iFeature =prtfeature
    ' Get the mid point of the selected curve
    ' assuming that the selected curve is linear
    Dim oMidPoint As Point2d = oDrawingCurve.MidPoint

    ' Set a reference to the TransientGeometry object.
    Dim oTG As TransientGeometry= ThisApplication.TransientGeometry

    Dim oLeaderPoints As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

    ' Create a few leader points.
    Call oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X - 1, oMidPoint.Y + 1))
 '   Call oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 10, oMidPoint.Y + 5))

    ' Create an intent and add to the leader points collection.
    ' This is the geometry that the leader text will attach to.
    Dim oGeometryIntent As GeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve)

    Call oLeaderPoints.Add(oGeometryIntent)

    ' Create text with simple string as input. Since this doesn't use
    ' any text overrides, it will default to the active text style.
    Dim sText As String= ifeat.Name ' & parameter

    Dim oLeaderNote As LeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, sText)
    End If
Next
End Sub

 

you can reach parameters using :

ifeat.Parameters.Item()

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 3 of 5

loicLPQZG
Contributor
Contributor

Hi, thank you for you response!

This helped out alot!

 

I have an additional question : If i select the sidewall of the feature i get an error. (in this case i am not able to select the start /end of the feature only the side.  Would you know how i could catch this ?

 

Many thanks in advance

0 Likes
Message 4 of 5

marcin_otręba
Advisor
Advisor
Accepted solution

with your model it would be easier, but anyway it is because selected curve model geometry is face, and when you select start or end you select edge, below code works with both possibilities:

 

 

Sub Main()

Dim ed As Edge
Dim oFace As Face
Dim oDrawingCurve As DrawingCurve = ThisApplication.CommandManager.Pick(kDrawingCurveSegmentFilter, "pick drawing curve").parent
If oDrawingCurve.ModelGeometry.type = 67119408 Then ' selected face curve
oFace = oDrawingCurve.ModelGeometry
add_leader(oFace,oDrawingCurve)
ElseIf oDrawingCurve.ModelGeometry.type = 67120176 Then 'selected edge curve
	ed=oDrawingCurve.ModelGeometry
For Each oFace In ed.Faces
    add_leader(oFace,oDrawingCurve)
Next 
End If
End Sub
Function add_leader(oface As Face, oDrawingCurve As DrawingCurve)
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oActiveSheet As Sheet = oDrawDoc.ActiveSheet
	Dim prtfeature As PartFeature = oface.CreatedByFeature
    If prtfeature.Type = 83998208   Then '151002368
	Dim ifeat As iFeature =prtfeature

    ' Get the mid point of the selected curve
    ' assuming that the selected curve is linear
    Dim oMidPoint As Point2d = oDrawingCurve.MidPoint

    ' Set a reference to the TransientGeometry object.
    Dim oTG As TransientGeometry= ThisApplication.TransientGeometry

    Dim oLeaderPoints As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

    ' Create a few leader points.
    Call oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X - 1, oMidPoint.Y + 1))
 '   Call oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 10, oMidPoint.Y + 5))

    ' Create an intent and add to the leader points collection.
    ' This is the geometry that the leader text will attach to.
    Dim oGeometryIntent As GeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve)

    Call oLeaderPoints.Add(oGeometryIntent)

    ' Create text with simple string as input. Since this doesn't use
    ' any text overrides, it will default to the active text style.
    Dim sText As String= ifeat.Name ' & parameter

    Dim oLeaderNote As LeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, sText)
    End If
End Function

 

 

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 5 of 5

loicLPQZG
Contributor
Contributor

Thank you @marcin_otręba for your help

When you explain it like that it makes a lot of sence !

 

0 Likes