Drawing sketch line linked to work plane

Drawing sketch line linked to work plane

malmal02122023
Advocate Advocate
1,499 Views
31 Replies
Message 1 of 32

Drawing sketch line linked to work plane

malmal02122023
Advocate
Advocate

Hello,

 

Could you help me please?

I am new in VBA ilogic

I would like to link a sketch line to work plane with offset 20 mm and use it to create section line.

I understand that the code shown below draws a line on the base view relative to its center.

Question: how can  build a line relative to the work plane located in the model and named A-A.

 

Thanks for advice

Dim SectionPoint_L As Point2d = oTG.CreatePoint2d(Left_X, oBaseView.Center.Y)
	Dim SectionPoint_R As Point2d = oTG.CreatePoint2d(Right_X, oBaseView.Center.Y)
	Dim SheetPoint_L As Point2d = SectionSketch.SheetToSketchSpace(SectionPoint_L)
	Dim SheetPoint_R As Point2d = SectionSketch.SheetToSketchSpace(SectionPoint_R)
	Dim SketchLine As Inventor.SketchLine = SectionSketch.SketchLines.AddByTwoPoints(SheetPoint_L, SheetPoint_R)

malmal02122023_0-1705176446376.png

 

0 Likes
Accepted solutions (1)
1,500 Views
31 Replies
Replies (31)
Message 21 of 32

A.Acheson
Mentor
Mentor

You have two options, offset or 2pointdistance. Offset would be easiest as it just needs two lines so very easy. 

drawing sketch dimension constraint help page here

 

 

 

Syntax

DimensionConstraints.AddOffset( Line As SketchLine, Entity As SketchEntity, TextPoint As Point2d, LinearDiameter As Boolean, [Driven] As Boolean ) As OffsetDimConstraint

 

Syntax

DimensionConstraints.AddTwoPointDistance( PointOne As SketchPoint, PointTwo As SketchPoint, Orientation As DimensionOrientationEnum, TextPoint As Point2d, [Driven] As Boolean ) As TwoPointDistanceDimConstraint


For use with sketch line to get the sketch point.

Syntax

SketchLine.StartSketchPoint() As SketchPoint

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 22 of 32

A.Acheson
Mentor
Mentor
Accepted solution

Here is one method to achieve this. Projecting the workplane to the sketch was difficult, you need to pick up the centerline in the drawing view to use as the entity. Simply using the workplaneproxy did not work. 

 

Once you have it working I suggest you make functions/sub routines in order to reuse objects as you can see there is some repetition setting in. The code below is clean up in terms of using consistent variable naming change as you would like. 

Sub Main()
	
    Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oSheet As Sheet = oDoc.ActiveSheet
    
    Dim oFirst_view As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Please select the main view")
    If oFirst_view Is Nothing Then Exit Sub
    
    If Not oFirst_view.ReferencedDocumentDescriptor.ReferencedDocumentType = kAssemblyDocumentObject Then Exit Sub
    
	Dim oComp As AssemblyDocument = oFirst_view.ReferencedDocumentDescriptor.ReferencedDocument
        
    Dim oOcc As ComponentOccurrence = oComp.ComponentDefinition.Occurrences.ItemByName("Skeleton test:1")
        
	Dim oSkeletonDoc As PartDocument = oOcc.Definition.Document
		
	Dim wpList As New List(Of String)
	
	Dim oWp As WorkPlane
	For Each oWp In oSkeletonDoc.ComponentDefinition.WorkPlanes
	      wpList.Add(oWp.Name)
	Next
	
	Dim wpSel As String = InputListBox("Work planes found", wpList, "", "Select work plane", "work plane found")
	
	If String.IsNullOrEmpty(wpSel) Then Return
	oWp = oSkeletonDoc.ComponentDefinition.WorkPlanes(wpSel)

	Dim oWPlaneProxy As WorkPlaneProxy 
	oOcc.CreateGeometryProxy(oWp, oWPlaneProxy) 
	
	oFirst_view.SetIncludeStatus(oWPlaneProxy, True) 
	oFirst_view.SetVisibility(oWPlaneProxy, False)

	Dim oSketch As DrawingSketch = oFirst_view.Sketches.Add
	oSketch.Edit()
	
	Dim oCenterLine1 As SketchLine
	For Each oCenterline As Centerline In oSheet.Centerlines
		If oCenterline.ModelWorkFeature Is oWPlaneProxy Then
			oCenterLine1 = oSketch.AddByProjectingEntity(oCenterline)
		End If
	Next
	
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	
	Dim oStartPoint As Point2d = oTG.CreatePoint2d(oCenterLine1.Geometry.StartPoint.X - 1, oCenterLine1.Geometry.StartPoint.Y + 1) 
    Dim oEndPoint As Point2d = oTG.CreatePoint2d(oCenterLine1.Geometry.EndPoint.X+1, oCenterLine1.Geometry.EndPoint.Y+1)
	
	Dim oSectionLine1 As SketchLine = oSketch.SketchLines.AddByTwoPoints(oStartPoint,oEndPoint)

	Dim oDimension1 As DimensionConstraint = oSketch.DimensionConstraints.AddTwoPointDistance _
											(oSectionLine1.StartSketchPoint, oCenterLine1.StartSketchPoint, _
											DimensionOrientationEnum.kVerticalDim, oSectionLine1.Geometry.MidPoint)
	
	Dim oDimension2 As DimensionConstraint = oSketch.DimensionConstraints.AddTwoPointDistance _
											(oSectionLine1.StartSketchPoint, oCenterLine1.StartSketchPoint, _
											DimensionOrientationEnum.kHorizontalDim, oCenterLine1.Geometry.StartPoint)
	
	Dim oDimension3 As DimensionConstraint = oSketch.DimensionConstraints.AddTwoPointDistance _
											(oSectionLine1.EndSketchPoint, oCenterLine1.EndSketchPoint, _
											DimensionOrientationEnum.kHorizontalDim,oCenterLine1.Geometry.EndPoint)
															
    oSketch.ExitEdit
	
	Dim oInsertionPoint As Point2d = oTG.CreatePoint2d((oFirst_view.Position.X + 10), (oFirst_view.Position.Y + 10))

	Dim oSectionView As SectionDrawingView = oSheet.DrawingViews.AddSectionView _
											(oFirst_view, oSketch, oInsertionPoint, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)

	oSectionView.SetDesignViewRepresentation(oSectionView.DesignViewRepresentation, True)
	oSectionView.ReverseDirection

	oSectionView.SectionDepth = 50/10
	oSectionView.ReverseDirection
			
End Sub

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 23 of 32

malmal02122023
Advocate
Advocate

Thank you very much. Is it possible to select by message box the section depth with offsets from work plane?

In this case there is expression for depth =50/10  offset is 50 mm and scale 1:10.

0 Likes
Message 24 of 32

malmal02122023
Advocate
Advocate

Could you answer for another question?
Is it possible to select several work planes at a time by input list box and create several separate sections. For example, select work planes 1, 2, 4, 7 and create separate horizontal sections for them with the selected offset and depth.
Thanks again.

0 Likes
Message 25 of 32

A.Acheson
Mentor
Mentor

Hi @malmal02122023 

 

If your looking to make universal version of your code to adjust to any workplane regardless of orientation vertical /horizontal this would be possible but would be definitely more involved. You would need to adjust your code to include x and y offsets automatically.

 

Having said that I tried working with

DrawingSketch.OffsetSketchEntitiesUsingDistance Method

 

and this allowed an offset line parralel to the centerline with minimal input to change direction other than to specify true / false. The only down side was the offset line was exactly the same length as the centerline which made dimesioning a challenge. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 26 of 32

malmal02122023
Advocate
Advocate

It would be great to have it in two axes x and y

0 Likes
Message 27 of 32

malmal02122023
Advocate
Advocate

But I'll have enough horizontal sections for now.
Just a question
Is it possible to make them by selecting several different working planes at the time?

0 Likes
Message 28 of 32

A.Acheson
Mentor
Mentor

The rule is currently set up to select only one plane and section. If you want more planes sectioned then run again or start making sub routines and supply the workplace selected as an argument.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 29 of 32

malmal02122023
Advocate
Advocate

Well then, how can I call up the window for setting the depth of the section and its offset?

0 Likes
Message 30 of 32

A.Acheson
Mentor
Mentor

I believe your depth is already been set after the view is created via 

oSectionView.SectionDepth = 50/10

You just need an input box if you want the user to customize it. Offset the value is hardcoded as 1cm again you just need to drive that value by inputbox. If you want a better way to do this then a win form would be the best. I would think that is more for streamlining at the end of your project. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 31 of 32

malmal02122023
Advocate
Advocate

Thank you very much.

0 Likes
Message 32 of 32

malmal02122023
Advocate
Advocate

Hello,

And if a visible plane XZ should be added to the new section view then it has to looked like this:

oWp = oSkeletonDoc.ComponentDefinition.Item("XZ Plane")

    'Create proxy object

    Dim oWPpx As WorkPlaneProxy

    Call oOcc.CreateGeometryProxy(oWp, oWPpx)

    'Set visibility

         	oSectionView.SetIncludeStatus(oWPpx, True) 
	oSectionView.SetVisibility(oWPpx, True)

 

Best regards