PDA

View Full Version : Rotating block jig in VB.NET



mcoffman
2009-06-12, 08:20 PM
Greetings!

I'm a VB.NET programmer and am just starting to delve into the AutoCAD API. I'm experimenting with Jigs and was wondering: Is there a way to insert a block using a Jig then rotate said block utilizing a jig to 'ghost' the rotation?

Thanks!
Michael

Bobby C. Jones
2009-06-17, 03:49 PM
The short answer is yes. If you're looking for example code your best bet is to do a search on th forums. If that doesn't turn up what you need come back to this thread and we'll work something up.

jason.lake
2009-06-23, 02:36 AM
Ok. I was excited when I found this post a few days ago since I had spent a day looking and not finding much. Since then I have found a few posts on how to create a block rotation jig in C#, but nothing in VB, so I've learned how to translate (kind of).

I came up with the following...



Class rotateBlockJig
Inherits EntityJig

Sub New(ByVal ent As Entity)
'mybase.new must be called because the base class entity jig does not have an accesible sub new that can be accesses with no arguments
MyBase.New(ent)
End Sub
Private lastMousePosition As Point3d = New Point3d()
Property jiggedBlockReference() As BlockReference
Get
Return Me.Entity
End Get
Set(ByVal value As BlockReference)

End Set
End Property
Property currentPosition() As Point3d
Get
Return jiggedBlockReference.position
End Get
Set(ByVal value As Point3d)

End Set
End Property

Protected Overrides Function Sampler(ByVal prompts As Autodesk.AutoCAD.EditorInput.JigPrompts) As Autodesk.AutoCAD.EditorInput.SamplerStatus

Dim jigOpt As JigPromptPointOptions = New JigPromptPointOptions("Select Rotation :")
jigOpt.UserInputControls = UserInputControls.Accept3dCoordinates
jigOpt.UserInputControls = UserInputControls.GovernedByOrthoMode

Dim res As PromptPointResult = prompts.AcquirePoint(jigOpt)

If res.Status <> PromptStatus.OK Then
Return SamplerStatus.Cancel
End If

If (res.Value.IsEqualTo(currentPosition, New Tolerance(0.1, 0.1))) Then
Return SamplerStatus.NoChange
End If

lastMousePosition = res.Value

Return SamplerStatus.OK

End Function

Protected Overrides Function Update() As Boolean

Dim oldPosition As Point2d = New Point2d(currentPosition.X, currentPosition.Y)
Dim newPosition As Point2d = New Point2d(lastMousePosition.x, lastMousePosition.Y)

jiggedBlockReference.Rotation = oldPosition.GetVectorTo(newPosition).Angle - Math.PI / 2

'code for use with dynamic blocks
For Each prop As DynamicBlockReferenceProperty In jiggedBlockReference.DynamicBlockReferencePropertyCollection
If prop.PropertyName.ToUpper = "LENGTH" Then
prop.Value = oldPosition.GetDistanceTo(newPosition)
End If
Next

Return True
End Function
End Class


This works well except that I can't constrain the rotation with ORTHO. I've got the "jigOpt.UserInputControls = UserInputControls.GovernedByOrthoMode" line in there, but it's not working.

To be frank I'm a newbie at .NET and programming in general. I've spent the last year learning and working with VBA and now we're moving to 64bit, so the .NET conversion was inevitable. I understand the basics of what's going on with the jig, but I just don't understand where the ORTHO comes into play.

For us newbies any explanation would be greatly appreciated.

Thanks,
JL

howardjosh
2009-08-21, 11:11 PM
This works well except that I can't constrain the rotation with ORTHO. I've got the "jigOpt.UserInputControls = UserInputControls.GovernedByOrthoMode" line in there, but it's not working.


I too am having this problem. If anyone has any clues please help.

I already know that eliminating a basepoint snap gets rid of the weird angle that gets applied when ortho is turned on, but I am jigging to make a custom line command. So that really isn't an option for me. I have noticed that the next time through the loop ortho doesn't have a problem. So my next try will be to artificially invoke the first run with a zero length line and see if that fixes it.

Edit: polar is also out of wack just like ortho; when trying to jig for a point using a rubber band snap

the more I think about it. The more certain I am the problem is in the ECS (entity coordinate system) within the update function. Anyone know how to modify the ecs of an entity.
A jig is creating a temporary database of some kind; So, uh... not only do I want to modify something that doesn't really exist, but I want to modify read only properties in it also