Create a line in the workplane position on drawing

Create a line in the workplane position on drawing

dialunau
Advocate Advocate
524 Views
2 Replies
Message 1 of 3

Create a line in the workplane position on drawing

dialunau
Advocate
Advocate

Hello everyone,

I have an assembly drawing in which I want to draw a line in the position of a workplane. The problem is that I don't know how to get the workplane coordinates from its position in the drawing view so I can create a line based on that position (so I can view the plane position relative to other parts in the assembly).

Does anyone know a method for this?

 

My code this far looks like this:

 

'Get the refference assembly
Dim oAssy As AssemblyDocument 
If ThisDoc.Document.AllReferencedDocuments.Item(1).DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
	oAssy = ThisDoc.Document.AllReferencedDocuments.Item(1)
Else
	MsgBox("The Active drawing does not contain an assembly document")
	Exit Sub
End If

Dim oCons As AssemblyConstraint = oAssy.ComponentDefinition.Constraints.Item(1)
Dim oEnt As Object

'Assumming oEnt is a workplane
oEnt = oCons.EntityOne

'Create the sketch
Dim oSheet As Sheet = ThisApplication.ActiveDocument.ActiveSheet
Dim oView As DrawingView = oSheet.DrawingViews.Item(1) 
Dim oSketch As Sketch

oSketch = oSheet.Sketches.Add()
oSketch.Edit
0 Likes
Accepted solutions (1)
525 Views
2 Replies
Replies (2)
Message 2 of 3

TomaszDąbrowski
Enthusiast
Enthusiast
Accepted solution

I would create a centerline, use it and make it invisible:

 

'Get the refference assembly
Dim oAssy As AssemblyDocument 
If ThisDoc.Document.AllReferencedDocuments.Item(1).DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
	oAssy = ThisDoc.Document.AllReferencedDocuments.Item(1)
Else
	MsgBox("The Active drawing does not contain an assembly document")
	Exit Sub
End If

Dim oCons As AssemblyConstraint = oAssy.ComponentDefinition.Constraints.Item(1)
Dim oEnt As Object

'Assumming oEnt is a workplane
oEnt = oCons.EntityOne

'Create the sketch
Dim oSheet As Sheet = ThisApplication.ActiveDocument.ActiveSheet
Dim oView As DrawingView = oSheet.DrawingViews.Item(1) 
Dim oSketch As Sketch
Dim oCL As Centerline = oSheet.Centerlines.AddByWorkFeature(oEnt, oView)
oCL.Visible = False
oSketch = oSheet.Sketches.Add()
oSketch.Edit
oSketch.SketchLines.AddByTwoPoints(oCL.StartPoint,oCL.EndPoint)
oSketch.ExitEdit

 

But in my opinion there is no need to use costraints, better use your workplane directly.

Instead of:

 

Dim oCons As AssemblyConstraint = oAssy.ComponentDefinition.Constraints.Item(1)
Dim oEnt As Object

'Assumming oEnt is a workplane
oEnt = oCons.EntityOne

 

You can have:

 

Dim oEnt As Object
oEnt = oAssy.ComponentDefinition.WorkPlanes.Item("YourWorkPlaneName")

 

Also please tak notice that such rule will create a new sketch every time you run it.

Message 3 of 3

dialunau
Advocate
Advocate

You're right, I don't need to call the constraint.

The code works now, creating the centerline did the trick.

Thank you.

0 Likes