How to select the drawingcurve of a part feature on the part drawing?

How to select the drawingcurve of a part feature on the part drawing?

Stakin
Collaborator Collaborator
1,565 Views
8 Replies
Message 1 of 9

How to select the drawingcurve of a part feature on the part drawing?

Stakin
Collaborator
Collaborator

Hi,everyone

I want to add bisector of an feature on a part drawing.

I use the DrawingView.DrawingCurves(feature name),but it can not work.

My code is as this:

Dim oEddownExtrude As ExtrudeFeature
oEddownExtrude=oView2.ReferencedDocumentDescriptor.ReferencedDocument.ComponentDefinition.Features("Eddown")

Dim oDCEnumerator As DrawingCurvesEnumerator
oDCEnumerator = oView2.DrawingCurves(oEddownExtrude

but the oDCEnumerator.Count=0,

 

Anyone know how to do this?

thanks

0 Likes
Accepted solutions (2)
1,566 Views
8 Replies
Replies (8)
Message 2 of 9

nmunro
Collaborator
Collaborator

Are you sure that the oEddownExtrude object is set to a non-null value after your code to retrieve it?

 

If that is OK you might want to review what edges  from that feature are actually "visible" in the selected drawing view. By visible I mean not obscured by edges from other features. The curves returned are not all the edges from the actual model feature, just the ones that are visible (could be solid or hidden line) in that view.

 

        


https://c3mcad.com

0 Likes
Message 3 of 9

Stakin
Collaborator
Collaborator

Hi,nmunro

thanks for your replying;

i want to add centerline of the extude feature (which was in the red circle)in the sectionview,but the code cann‘t work。

screencast.JPG

here is my whole code,ipt and idw。

Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.ActiveDocument 
Dim oSheet As Sheet
	oSheet = oDrawingDoc.Sheets.Item(1)
Dim oTG As TransientGeometry
	oTG = ThisApplication.TransientGeometry
Dim oView1 As DrawingView
	oView1=oSheet.DrawingViews.Item(1)	
Dim oView2 As SectionDrawingView
Dim oDrawingSketch As DrawingSketch
Dim oCropSketch As DrawingSketch

Dim oPoint1 As Point2d
Dim oPoint2 As Point2d
Dim oPoint3 As Point2d
Dim oPoint4 As Point2d
Dim oMPoint1 As Point
Dim oMPoint2 As Point
Dim TubeDia As Double
Dim innerDia As Double
Dim thickness As Double
Dim mergeNum As Double
Dim HeightNum As Double
Dim angleNum As Double
Dim omx1 As Double
Dim omy1 As Double
Dim omz1 As Double
Dim omx2 As Double
Dim omy2 As Double
Dim omz2 As Double
TubeDia=200
innerDia = 3000
thickness = 1000
mergeNum = 200
HeightNum = - 600
angleNum =47/3
omx1 = (innerDia / 2 - mergeNum) * Cos(angleNum / 180 * PI) / 10
omy1 = (innerDia / 2 - mergeNum) * Sin(angleNum / 180 * PI) / 10
omz1 = HeightNum / 10
omx2 = (innerDia / 2 + mergeNum + thickness) * Cos(angleNum / 180 * PI) / 10
omy2 = (innerDia / 2 + mergeNum + thickness) * Sin(angleNum / 180 * PI) / 10
omz2 = HeightNum / 10

oMPoint1 = oTG.CreatePoint(omx1, omy1, omz1)
oMPoint2 = oTG.CreatePoint(omx2, omy2, omz2)

Dim oWorkPoint1 As WorkPoint
Dim oWorkPoint2 As WorkPoint

oWorkPoint1=oView1.ReferencedDocumentDescriptor.ReferencedDocument.ComponentDefinition.WorkPoints.AddFixed(oMPoint1, True)
oWorkPoint2=oView1.ReferencedDocumentDescriptor.ReferencedDocument.ComponentDefinition.WorkPoints.AddFixed(oMPoint2, True)

oPoint1 = oView1.ModelToDrawingViewSpace(oWorkPoint1.Point)
oPoint2 = oView1.ModelToDrawingViewSpace(oWorkPoint2.Point)
oPoint3 = oView1.DrawingViewToSheetSpace(oTG.CreatePoint2d((oPoint1.X + oPoint2.X) / 2 , (oPoint1.Y + oPoint2.Y) / 2 -1))




oDrawingSketch = oView1.Sketches.Add
oDrawingSketch.Edit
Dim oSketchLine As SketchLine
oSketchLine = oDrawingSketch.SketchLines.AddByTwoPoints(oPoint1, oPoint2)
oDrawingSketch.ExitEdit
Dim View_Lable As String
	View_Lable=If(i<26,"",If(i<26*27,"",Chr(65+Floor((i-26)/(26*26))-1))&Chr(64+Floor((i-26*26*Floor((i-26)/(26*26)))/26)))&Chr(65+i-26*Floor(i/26))
oView2 = oSheet.DrawingViews.AddSectionView(oView1, _
	oDrawingSketch, oPoint3, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, , , View_Lable,, 1, 0)	
Dim oVector2d As Vector2d
Dim oUnitVector2d As UnitVector2d
Dim oRoAngle As Double
oVector2d = oTG.CreateVector2d(omx2 - omx1, omy2 - omy1)
oUnitVector2d = oTG.CreateUnitVector2d(1, 0)
oRoAngle = oVector2d.AsUnitVector.AngleTo(oUnitVector2d)
oView2.RotateByAngle(oRoAngle)
Dim oEddownExtrude As ExtrudeFeature
oEddownExtrude=oView2.ReferencedDocumentDescriptor.ReferencedDocument.ComponentDefinition.Features("Eddown")
Dim oDCEnumerator As DrawingCurvesEnumerator
oDCEnumerator = oView2.DrawingCurves(oEddownExtrude)
MessageBox.Show(oDCEnumerator.Count, "oDCEnumerator.Count")
'Dim oCenterLine As Centerline 
'oCenterLine =oSheet.Centerlines.AddBisector(oDCEnumerator.Item(1),oDCEnumerator.Item(2))

’Can you check the code to find where is wrong? 

thank you again。

0 Likes
Message 4 of 9

Stakin
Collaborator
Collaborator

I think the most critical question is how to use the DrawingView.DrawingCurves(ModelObject)?

The Modelobject maybe :

Optional input object that specifies the object from the model for which the corresponding drawing view curves need to be retrieved. This could be an Edge, Face, PartFeature, Sketch, SketchEntity, Sketch3D, SketchEntity3D, ComponentOccurrence, or the proxies to any of these. If not specified, all the edges from the drawing view are returned.


Is there a other better way?

tt.JPG

0 Likes
Message 5 of 9

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Stakin 

The lines you see in the section view representing the extrude can not be retrieved with oView2.DrawingCurves(oEddownExtrude)... This will return zero curves because the curves you is not a result of the extrude itself but the sectioning of the face created by the extrude (if that makes any sense)...

 

You can however get that face and check each curve in the view to see if the curves modelgeometry is that face 🙂

In your attached idw, this code will produce the centerline:

Dim oSheet As Sheet = ActiveSheet.Sheet
Dim oView As DrawingView = oSheet.DrawingViews(2)
Dim oDoc As PartDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oFeature As ExtrudeFeature = oDoc.ComponentDefinition.Features("Eddown")
Dim oCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each oFace As Face In oFeature.Faces
If TypeOf(oFace.Geometry) Is Cylinder
For Each oCurve As DrawingCurve In oView.DrawingCurves
If oCurve.ModelGeometry Is oFace Then oCol.Add(oCurve)
Next
End If
Next
Dim oCenterLine As Centerline 
oCenterLine =oSheet.Centerlines.AddBisector(oSheet.CreateGeometryIntent(oCol(1)),oSheet.CreateGeometryIntent(oCol(2)))
Message 6 of 9

Stakin
Collaborator
Collaborator

Hi,@JhoelForshav 

I tried your code,but still have two problem,

(1)cylinder profile feature,still have some position cann't find the featurecurve in the drawing,such as C-C,D-D,I-I views, Set different  “oCr” values to correspond to different views

"oCr=2"------>B-B

"oCr=3"------>C-C

"oCr=4"------>D-D

"oCr=5"------>E-E

"oCr=6"------>F-F

"oCr=7"------>G-G

"oCr=8"------>H-H

"oCr=9"------>I-I

"oCr=10"------>J-J

Dim oSheet As Sheet = ActiveSheet.Sheet
Dim oCr As Integer
oCr = 2

Dim oView As DrawingView = oSheet.DrawingViews(oCr)
Dim oCim As Integer

Select Case oCr-1
Case 1
    oFeatureName="Eddown1"
Case 2
    oFeatureName="someup2"	
Case 3
    oFeatureName="someup1"
Case 4
	oFeatureName = "Eddown"
Case 5
	oFeatureName = "Edup2"	
Case 6
	oFeatureName = "Edup3"
Case 7
	oFeatureName = "Edup5"
Case 8
	oFeatureName = "Edup4"
Case Else	
	Exit Sub
End Select
Dim oDoc As PartDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oFeature As ExtrudeFeature = oDoc.ComponentDefinition.Features(oFeatureName)
Dim oCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each oFace As Face In oFeature.Faces
If TypeOf(oFace.Geometry) Is Cylinder
For Each oCurve As DrawingCurve In oView.DrawingCurves
If oCurve.ModelGeometry Is oFace Then oCol.Add(oCurve)
Next
End If
Next
Dim oCenterLine As Centerline 
oCenterLine = oSheet.Centerlines.AddBisector(oSheet.CreateGeometryIntent(oCol(1)), oSheet.CreateGeometryIntent(oCol(2)))
  Dim oCurve1 As DrawingCurve, oCurve2 As DrawingCurve
    oCurve1 = oCol(1)
    oCurve2 = oCol(2)
    Dim oIntent1 As GeometryIntent, oIntent2 As GeometryIntent
    oIntent1 = oSheet.CreateGeometryIntent(oCurve2)
    oIntent2 = oSheet.CreateGeometryIntent(oCurve1)    
    Dim oTextPos As Point2d
	Dim oTG As TransientGeometry
	oTG = ThisApplication.TransientGeometry	
    oTextPos = oTG.CreatePoint2d(oView.Position.X-2, oView.Center.Y)    
      Dim oLinearForeshortenedDim As LinearGeneralDimension
    oLinearForeshortenedDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oTextPos, oIntent1, oIntent2)
	oLinearForeshortenedDim.Text.FormattedText = "Φ" & oLinearForeshortenedDim.Text.FormattedText
	
	

(2)If have the feature is rectangle shape? such as J-J View?How to add centerline and dimension for it?

 

 

Hope to get your advice,thanks for your help.

0 Likes
Message 7 of 9

JhoelForshav
Mentor
Mentor

Hi @Stakin 

Sorry, but it seems like the curves in those views are not representing the feature you're trying to find.

All of them are representing Extrusion1. You can run something like this rule and pick the lines to see for yourself:

Dim oSeg As DrawingCurveSegment = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Pick line")
Dim oCurve As DrawingCurve = oSeg.Parent
Dim oFace As Face = oCurve.ModelGeometry
For Each oFeature As PartFeature In oCurve.Parent.ReferencedDocumentDescriptor.ReferencedDocument.ComponentDefinition.Features
	For Each fFace As Face In oFeature.Faces
		If fFace Is oFace Then MsgBox(oFeature.Name)
	Next
Next
0 Likes
Message 8 of 9

Stakin
Collaborator
Collaborator
Accepted solution

Hi@JhoelForshav ,thank you for your help.

I don't know why this happens,I delete the sick feature,and regenerate it,now,it is work right.

I change the code to collect the drawingcurves of the feature,

Whether it is a round hole or a rectangular hole, until now it can work normally。

Dim oSheet As Sheet = ActiveSheet.Sheet
Dim oCr As Integer
oCr = 10

Dim oView As DrawingView = oSheet.DrawingViews(oCr)
Dim oCim As Integer

Select Case oCr-1
Case 1
    oFeatureName="Eddown1"
Case 2
    oFeatureName="someup2"	
Case 3
    oFeatureName="someup1"
Case 4
	oFeatureName = "Eddown"
Case 5
	oFeatureName = "Edup2"	
Case 6
	oFeatureName = "Edup3"
Case 7
	oFeatureName = "Edup5"
Case 8
	oFeatureName = "Edup4"
Case 9
	oFeatureName = "Edup6"
Case Else	
	Exit Sub
End Select
Dim oDoc As PartDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oFeature As ExtrudeFeature = oDoc.ComponentDefinition.Features(oFeatureName)
Dim oCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

For Each oCurve As DrawingCurve In oView.DrawingCurves	
	For Each oFace As Face In oFeature.Faces
		If oCurve.ModelGeometry Is oFace Then oCol.Add(oCurve)
	Next
Next

Dim oCenterLine As Centerline 

  Dim oCurve1 As DrawingCurve, oCurve2 As DrawingCurve
    oCurve1 = oCol(1)
    oCurve2 = oCol(2)
    Dim oIntent1 As GeometryIntent, oIntent2 As GeometryIntent
    oIntent1 = oSheet.CreateGeometryIntent(oCurve2)
    oIntent2 = oSheet.CreateGeometryIntent(oCurve1)  
	oCenterLine = oSheet.Centerlines.AddBisector(oIntent1,oIntent2)
    Dim oTextPos As Point2d
	Dim oTG As TransientGeometry
	oTG = ThisApplication.TransientGeometry	
    oTextPos = oTG.CreatePoint2d(oView.Position.X-2, oView.Center.Y)    
      Dim oLinearForeshortenedDim As LinearGeneralDimension
    oLinearForeshortenedDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oTextPos, oIntent1, oIntent2)
	oLinearForeshortenedDim.Text.FormattedText = "Φ" & oLinearForeshortenedDim.Text.FormattedText
	
	
0 Likes
Message 9 of 9

Stakin
Collaborator
Collaborator

Hi@JhoelForshav

 
I don't know why this error occurs randomly, any feature may not be recognized, and only recognized as "ExtrudeFeature1". When an error occurs, the feature needs to be deleted and regenerated every time. Do you know how this is caused?

 

0 Likes