TheSwamp
Code Red => VB(A) => Topic started by: ML on December 06, 2007, 12:44:23 PM
-
Hello,
I have a bit of code that simply allows me to pick (my objects) on screen, then pick a point.
With that:
I was wondering if anyone has a way or method that I can take the selection set's picked point and move the sset to 0,0
Also, I would like to make 0,0 the basepoint
Any ideas?
Thanks
Mark
-
Here is a simple sub for moving something
Sub Example_Move()
' This example creates a circle and then performs
' a move on that circle.
' Create the circle
Dim circleObj As AcadCircle
Dim center(0 To 2) As Double
Dim radius As Double
center(0) = 2#: center(1) = 2#: center(2) = 0#
radius = 0.5
Set circleObj = ThisDrawing.ModelSpace.AddCircle(center, radius)
ZoomAll
' Define the points that make up the move vector
Dim point1(0 To 2) As Double
Dim point2(0 To 2) As Double
point1(0) = 0: point1(1) = 0: point1(2) = 0
point2(0) = 2: point2(1) = 0: point2(2) = 0
MsgBox "Move the circle 2 units in the X direction.", , "Move Example"
' Move the circle
circleObj.Move point1, point2
ZoomAll
MsgBox "Move completed.", , "Move Example"
End Sub
-
Post what you have and we can change it. It seems like your almost there.
dim ZeroZero(2) as Double
ZeroZero(0)=0:ZeroZero(1)=0:ZeroZero(2)=0
For each Obj in SS
obj.move YourPickedPoint, ZeroZero
next obj
-
The only way I know to make 0,0 your base point in VBA is this:
ThisDrawing.SendCommand "base" & vbCr "0,0" &vbCr (not tested)
It's crude but effective. Add it to CmdrDuhs' code, and there you go.
-
Yes right from the help screen :)
I was already looking at that
I need to move a selection set and there is no method that I know of for doing that
I tried something weird like
Dim Ent as Acadentity
Ent = Sset
Ent.move Pnt1, Pnt2
Because Entities can be moved however that may not be the best method either.
Anymore suggestions?
Thanks
Mark
-
Ahhhhhh, I was almost there LOL
Here is your code CM
dim ZeroZero(2) as Double
ZeroZero(0)=0:ZeroZero(1)=0:ZeroZero(2)=0
For each Obj in SS
obj.move YourPickedPoint, ZeroZero
next obj
I tried using the object.move method but I did not loop through each obj in the sset
Let me go try
Thanks,
Mark
-
what about setvar INSBASE?
ThisDrawing.SetVariable "INSBASE", "0,0,0"
-
Hey deegeecees
Sometimes we have to do it! :)
Thanks
Mark
-
what about setvar INSBASE?
ThisDrawing.SetVariable "INSBASE", "0,0,0"
Yup. That too.
-
Yes sir!
CM! You the man!
-
glad it worked
-
The move is working great, thanks guys!
Now I know how to move an sset but still the inbase variable is not setting ?
Here is what I got
Sub MoveSsettoZeroZero()
On Error Resume Next
ThisDrawing.SelectionSets.Item("Selection1").Delete
Dim Sset As AcadSelectionSet
Dim Obj As AcadObject
Dim ZeroZero(0 To 2) As Double
Dim Pnt As Variant
ZeroZero(0) = 0: ZeroZero(1) = 0: ZeroZero(2) = 0
Set Sset = ThisDrawing.SelectionSets.Add("Selection1")
Sset.SelectOnScreen
Debug.Print "Selection Set " & "("; Sset.Name; ")" & " was created"
Pnt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Pickpoint")
Debug.Print "Point = "; Pnt(0) & " , " & Pnt(1)
For Each Obj In Sset
Obj.Move Pnt, ZeroZero
Next Obj
ThisDrawing.SetVariable "INSBASE", ("0, 0, 0")
ThisDrawing.SelectionSets.Item("Selection1").Delete
End Sub
-
Ooops
Forget the parenthesis
I am not using them and it is still not working?
Mark
-
what happens if you type INSBASE at the command line?
-
It returns the base point
However, if you want to set a base point (at least by picking) in a drawing, you now use base
-
As Dec. suggested
This is working fine:
ThisDrawing.SendCommand "base" & vbCr & "0,0" & vbCr
Yes, i would prefer the setvariable method but, it is not big deal to send "A" command to the command line.
-
It looks like you have to use a variant to set INSBASE
-
public sub SetInsBase()
Dim sysVarName As String
Dim sysVarData As Variant
Dim DataType As Integer
Dim arrayData3D(0 To 2) As Double
sysVarName = "INSBASE"
arrayData3D(0) = 1#: arrayData3D(1) = 1#: arrayData3D(2) = 0
sysVarData = arrayData3D ' 3D array data
ThisDrawing.SetVariable sysVarName, sysVarData
end sub
-
I tested that at 1,1,0 and then 3,1,0 and it worked both times
-
WOW!
I understand what is happening there but I think in this case I will stick with
ThisDrawing.SendCommand "base" & vbCr & "0,0,0" & vbCr
Just to keep it a bit cleaner
Good to know for future reference.
Thanks for the help CM!
M
-
As CmdrDuh shows, entering the value for INSBASE as a 3dpoint value it works. Why? Well, look at the definition in help:
Type: 3D-point
Saved in: Drawing
Initial value: 0.0000,0.0000,0.0000
Why does entering "0,0,0" work at the command line and not in VBA? Because the command line version does the conversion to a 3d point array for you. When operating with any 3d point in any program language, though, you must be the one to make sure to pass the data in the format it is expected to be.
HTH for any future items of a similar nature....such as when you insert a block using InsertBlock....you wouldn't use "1,1,0" as the insertion point, would you? And just like the initial portion of this thread, you specify a true 2d/3d point to move from/to and not the string version of it.
-
Hey Jeff
I totally understand what you are saying.
God, look at the posts we did on Raster Images; plenty of info on that subject.
I really actually learned a real lot from that post.
I was not doubting CM for one sec and I understand why it is done like that; it is just that I needed a quick down and dirty macro for this project that I may or may not use again.
However, I will keep that bit of code around for future use.
Mark
-
Ok,
I did put that code in and it works great!
Thanks CM - Jeff!
Mark
-
Actually
Those 8 lines of code can do the same thing with 3 lines.
The critical part was getting the 3 points into the variable.
Mark
Dim Basepnt(0 To 2) As Double
Basepnt(0) = 0#: Basepnt(1) = 0#: Basepnt(2) = 0#
ThisDrawing.SetVariable "INSBASE", Basepnt
-
Here is the whole thing if anyone is interested:
Mark
Sub MoveSsettoZeroZero()
On Error Resume Next
ThisDrawing.SelectionSets.Item("Sset1").Delete
Dim Sset As AcadSelectionSet
Dim Obj As AcadObject
Dim Pnt As Variant
Dim ZeroZero(0 To 2) As Double
ZeroZero(0) = 0: ZeroZero(1) = 0: ZeroZero(2) = 0
Set Sset = ThisDrawing.SelectionSets.Add("Sset1")
Sset.SelectOnScreen
'Debug.Print "Selection Set " & "("; Sset.Name; ")" & " was created"
Pnt = ThisDrawing.Utility.GetPoint(, "Pickpoint")
'Debug.Print "Point = "; Pnt(0) & " , " & Pnt(1)
For Each Obj In Sset
Obj.Move Pnt, ZeroZero
Next Obj
Dim Basepnt(0 To 2) As Double
Basepnt(0) = 0#: Basepnt(1) = 0#: Basepnt(2) = 0#
ThisDrawing.SetVariable "INSBASE", Basepnt
ThisDrawing.SelectionSets.Item("Sset1").Delete
End Sub
-
Dim Basepnt(0 To 2) As Double
Basepnt(0) = 0#: Basepnt(1) = 0#: Basepnt(2) = 0#
ThisDrawing.SetVariable "INSBASE", Basepnt
To shorten it further, when you dimension your variable as a Double, the default value for a Double is 0. SO this could be written as
Dim Basepnt(0 To 2) As Double
ThisDrawing.SetVariable "INSBASE", Basepnt
However, while this CAN be done it is usually preferable to show the true intent, as you have done. Just an FYI.
-
Cool
That is good to know, thanks Jeff!
I agree though, it is good to have the true intent incase it needs to be adjusted above 0 later
Thanks
Mark