Sketch Move Method

Sketch Move Method

autodeskuser58
Explorer Explorer
245 Views
3 Replies
Message 1 of 4

Sketch Move Method

autodeskuser58
Explorer
Explorer

Hi, I am faced with the following problem.  I have sample code for Sketch. There is a Boolean Copy parameter, if this parameter is enabled, the method works, but if it is disabled, an Unknown error occurs. I need to move it without a copy. I'm just taking the sketch as a circle. 

 

  
    ' Check to make sure a sketch is open.
    If Not TypeOf ThisApplication.ActiveEditObject Is Sketch Then
        MsgBox( "A sketch must be active.")
        Exit Sub
    End If

    ' Set a reference to the active sketch.
    Dim oSketch As Sketch
    oSketch = ThisApplication.ActiveEditObject
    
    ' Create a vector along the x-axis.
    Dim oVec As Vector2d
     oVec = ThisApplication.TransientGeometry.CreateVector2d(5, 0)
    
    Dim oSketchObjects As ObjectCollection
     oSketchObjects = ThisApplication.TransientObjects.CreateObjectCollection
    
    ' Get all entities in the sketch
    Dim oSketchEntity As SketchEntity
    For Each oSketchEntity In oSketch.SketchEntities
        oSketchObjects.Add(oSketchEntity)
    Next
    
    ' Move all sketch objects along x-axis by 5 units.
    ' This will move all the text boxes and images in
    ' the sketch as well since these have sketch lines
    ' as boundary geometry or a sketch point as an
    ' origin point.
    Call oSketch.MoveSketchObjects(oSketchObjects, oVec, False) 

 

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

WCrihfield
Mentor
Mentor

Hi @autodeskuser58.  It sounds like something in that sketch is constrained in a way that it will not allow moving in that direction.  The PlanarSketch.MoveSketchObjects method that you are using also has a fourth input parameter which is optional, but may be needed in this case.  It is asking if you want to remove constraints.  You can try specifying False for the Copy input, but try specifying True for removing constrains, to see if that is the issue.  If that is the issue, then you may have to edit the constraints within that sketch in an appropriate way before it will allow this move, and still keep other existing constraints in place.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

autodeskuser58
Explorer
Explorer

Unfortunately, just adding the fourth parameter didn't help, but I manually removed the dependency and after that the rule worked as it should. It remains to somehow delete it through the code.

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor
Accepted solution

I am not sure I understand what you meant by "It remains to somehow delete it through the code.", but it kind of sounds like you may want to figure out a way to edit the constraints in the sketch, and delete the one or more constraint that may be causing the issue, before using the move method.  If so, then we can iterate through the PlanarSketch.GeometricConstraints and inspect each base type GeometricConstraint object, to see if it one of the more specific Type (types derived from that Type) of geometric constraints like a GroundConstraint, which could indicate projected geometry, if not grounded on purpose.  Then if so, delete that constraint.  We can use the 'TypeOf' operator for checking their Type, if needed.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes