SetByPoint throwing unknown error.

SetByPoint throwing unknown error.

dylanTEV9W
Advocate Advocate
541 Views
3 Replies
Message 1 of 4

SetByPoint throwing unknown error.

dylanTEV9W
Advocate
Advocate

Hi everyone I'm having an issue with the set by point command on the workpoint object. It's throwing an error even though I have it set as adaptive and am inputting a point (I've also tried setting it with a new create point command in the transient geometry object and without). 

 

Here is the code I'm running in VB.Net, I've attached the part file below. 

 

Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click 'Parameter print out for debugging.

'Get part document information 'change to assembly

Dim part_doc As PartDocument ' get the active part document

part_doc = _invApp.ActiveDocument 'set part_doc as the active part document

Dim trans_geo As TransientGeometry 'get transient geometry from the application

trans_geo = _invApp.TransientGeometry 'set trans_geo as Transient Geometry object

Dim component_definition As ComponentDefinition 'Get the component definition from the part document.

component_definition = part_doc.ComponentDefinition

Dim active_part As PartComponentDefinition ' define the active component

active_part = part_doc.ComponentDefinition ' set the active component

Dim sketch As Sketch = active_part.Sketches.Item(1) 'get the active sketch

Dim point As Point = sketch.SketchPoints.Item(1).Geometry3d ' get the point.

Dim wp As WorkPoint = active_part.WorkPoints.Item("Work Point1") 'Get the work point

wp.Adaptive = True

wp.SetByPoint(point) 'set the workpoint to the point geometry.

'wp.SetByPoint(trans_geo.CreatePoint(1, 1, 1)) 'Alternate set point method also produces error.

End Sub

 

 

0 Likes
Accepted solutions (1)
542 Views
3 Replies
Replies (3)
Message 2 of 4

dylanTEV9W
Advocate
Advocate

Was just messing around and found that using SetFixed works fine provided I turn the adaptive option off (which is fine the only reason I had it on was I thought it might make the code work.) Still not sure why SetByPoint wasn't working. 

 

Here is the functional code. 

 

Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click 'Parameter print out for debugging.

'Get part document information 'change to assembly

Dim part_doc As PartDocument ' get the active part document

part_doc = _invApp.ActiveDocument 'set part_doc as the active part document

Dim trans_geo As TransientGeometry 'get transient geometry from the application

trans_geo = _invApp.TransientGeometry 'set trans_geo as Transient Geometry object

Dim component_definition As ComponentDefinition 'Get the component definition from the part document.

component_definition = part_doc.ComponentDefinition

Dim active_part As PartComponentDefinition ' define the active component

active_part = part_doc.ComponentDefinition ' set the active component

Dim sketch As Sketch = active_part.Sketches.Item(1) 'get the active sketch

Dim point As Point = sketch.SketchPoints.Item(1).Geometry3d ' get the point.

Dim wp As WorkPoint = active_part.WorkPoints.Item("Work Point1") 'Get the work point

'wp.Adaptive = True

wp.SetFixed(point) 'set the workpoint to the point geometry.

'wp.SetByPoint(trans_geo.CreatePoint(1, 1, 1)) 'Alternate set point method also produces error.

End Sub

0 Likes
Message 3 of 4

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@dylanTEV9W ,

 

Actually, SetByPoint() method accepts Vertex, SketchPoint, or SketchPoint3D object as a input parameter. Try below modified code.

 

Dim point As SketchPoint = sketch.SketchPoints.Item(1)' get the point.

Dim wp As WorkPoint = active_part.WorkPoints.Item("Work Point1") 'Get the work point
wp.Adaptive = True

wp.SetByPoint(point)

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 4 of 4

dylanTEV9W
Advocate
Advocate

Thanks for clarifying that Chandra. Due to the nature of what I'm trying to code SetFixed() will work better since I'm reading coordinates from a seperatre text file. But I'm glad to know SetByPoint() works as well.

0 Likes