Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Adding section view with a sketch inherited from a model via iLogic

jeremiasfriesen
Contributor

Adding section view with a sketch inherited from a model via iLogic

jeremiasfriesen
Contributor
Contributor

Hi!
I´m trying to figure out a problem all day now and I am really frustrated by now, so I hope someone can help me out. I want to automate the process of adding section views to a sheet. To ensure consistency over a range of possible product variations, I had the idea of adding a sketch in the 3D Model that is always at the right place. This sketch could then be inherited into the drawing, which represents a straight line in the drawing which then could be used to create the section view. When doing it by hand, everything works fine, but I can´t figure out how to reference the sketch when adding a section view via iLogic. The command requires a DrawingSketch object, however the sketch that I want to use from the model and is a planar sketch. I access it through the ReferencedDocument member, which disconnects it from the drawing, so it makes sense that it isn´t a DrawingSketch. This however makes it so it doesn´t work with the command. I can´t figure out how to access inherited sketches in the drawing, as the Sketches enumerator from the sheet and from the view are both empty. Is there a way to access the inherited drawings from the model that are shown on a sheet/a drawing view? If so, how?

Thanks in advance!

0 Likes
Reply
Accepted solutions (2)
363 Views
5 Replies
Replies (5)

abdullah_elq
Advocate
Advocate
Have you considered using a workplane instead of a sketch to represent your section line? That might be a bit easier.
0 Likes

jeremiasfriesen
Contributor
Contributor

Could work, but I still wouldn´t know how to correctly reference the workplane in order to add a section drawing...Somehow it is really difficult to access the inherited objects

0 Likes

abdullah_elq
Advocate
Advocate
Accepted solution

Give this a shot:

Dim oDrawingView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select your Drawing View") 

Dim oSheet As Sheet = oDrawingView.Parent

'Get the part refrence
Dim oPartDoc As PartDocument = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument

Dim oPartCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition

'Assumes that you have a WorkPlane in your part named "SectionLinePlane"
Dim SketchLineWorkPlane As WorkPlane = oPartCompDef.WorkPlanes("SectionLinePlane")

'Include the WorkPlane into your drawing View
oDrawingView.SetIncludeStatus(SketchLineWorkPlane, True)

'Determine which CenterLine relates to your WorkPlane
Dim oTargetCenterLine As Centerline
For Each oCenterLine As Centerline In oSheet.Centerlines
	If oCenterLine.ModelWorkFeature is SketchLineWorkPlane Then
		oTargetCenterLine = oCenterLine
	End If
Next

'Draw the sketch for your projected view
Dim SectionLineSketch As DrawingSketch = oSheet.Sketches.Add

SectionLineSketch.Edit

SectionLineSketch.SketchLines.AddByTwoPoints(oTargetCenterLine.StartPoint, oTargetCenterLine.EndPoint)

SectionLineSketch.ExitEdit

'Place the New View

Dim ProjectedViewPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oDrawingView.Center.X + 20, oDrawingView.Center.Y)

oSheet.DrawingViews.AddProjectedView(oDrawingView, ProjectedViewPoint, drawingviewstyleenum.kFromBaseDrawingViewStyle)
0 Likes

jeremiasfriesen
Contributor
Contributor

This looks promising, I will give it a shot later this day. Thanks!

0 Likes

jeremiasfriesen
Contributor
Contributor
Accepted solution

Okay I did it a slightly different way, but your idea helped me quite a lot.

Dim oDoc As DrawingDocument = ThisDoc.Document

Dim oSheet As Sheet = ActiveSheet.Sheet

Dim oView As DrawingView = oSheet.DrawingViews.Item(1)

Dim oPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oView.Left - 20, 0)

Dim oTargetLine As DrawingCurve

For Each oCurve As DrawingCurve In oView.DrawingCurves
	Dim oModelGeom As SketchLineProxy
	Try
		oModelGeom = oCurve.ModelGeometry
	Catch 
		oModelGeom = Nothing
	End Try
	If oModelGeom IsNot Nothing
		If oModelGeom.Parent.Name = "NameOfSketchInModel"
			oTargetLine = oCurve
		End If
	End If
	
Next 

Dim newSketch As DrawingSketch = oView.Sketches.Add

newSketch.Edit

newSketch.SketchLines.AddByTwoPoints(oView.SheetToDrawingViewSpace(oTargetLine.StartPoint), oView.SheetToDrawingViewSpace(oTargetLine.EndPoint))

newSketch.ExitEdit

newSketch.Name = "Schnitt Spannkopf"

Dim oSectionView As SectionDrawingView

oSectionView = oSheet.DrawingViews.AddSectionView(oView, newSketch, oPoint, DrawingViewStyleEnum.kFromBaseDrawingViewStyle)
oSectionView.ReverseDirection

As you can see I managed to use the sketch, but instead of filtering for wether the Curve is derived from a WorkPlane, I directly filtered for the parent of the proxy of the drawing curve. This allowed me to specifically target lines that are derived from a certain sketch, as I plan to create several section views at once. I guess the same approach would work with WorkPlanes, but I just used what I already had.

 

Again, thanks 🙂