TheSwamp

Code Red => VB(A) => Topic started by: ML on December 06, 2007, 12:44:23 PM

Title: Sset Move and make basepoint 0,0
Post 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
Title: Re: Sset Move and make basepoint 0,0
Post by: David Hall on December 06, 2007, 12:54:11 PM
Here is a simple sub for moving something
Code: [Select]
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
Title: Re: Sset Move and make basepoint 0,0
Post by: David Hall on December 06, 2007, 12:56:27 PM
Post what you have and we can change it.  It seems like your almost there.
Code: [Select]
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
Title: Re: Sset Move and make basepoint 0,0
Post by: deegeecees on December 06, 2007, 12:58:41 PM
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.
Title: Re: Sset Move and make basepoint 0,0
Post by: ML on December 06, 2007, 12:59:29 PM
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


Title: Re: Sset Move and make basepoint 0,0
Post by: ML on December 06, 2007, 01:02:45 PM

Ahhhhhh, I was almost there LOL
Here is your code CM

Code: [Select]
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
Title: Re: Sset Move and make basepoint 0,0
Post by: David Hall on December 06, 2007, 01:04:19 PM
what about setvar INSBASE?
ThisDrawing.SetVariable "INSBASE", "0,0,0"
Title: Re: Sset Move and make basepoint 0,0
Post by: ML on December 06, 2007, 01:06:17 PM

Hey deegeecees

Sometimes we have to do it! :)

Thanks

Mark
Title: Re: Sset Move and make basepoint 0,0
Post by: deegeecees on December 06, 2007, 01:06:38 PM
what about setvar INSBASE?
ThisDrawing.SetVariable "INSBASE", "0,0,0"

Yup. That too.
Title: Re: Sset Move and make basepoint 0,0
Post by: ML on December 06, 2007, 01:06:45 PM
Yes sir!

CM! You the man!

Title: Re: Sset Move and make basepoint 0,0
Post by: David Hall on December 06, 2007, 01:09:43 PM
glad it worked
Title: Re: Sset Move and make basepoint 0,0
Post by: ML on December 06, 2007, 01:17:12 PM

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

Code: [Select]
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

Title: Re: Sset Move and make basepoint 0,0
Post by: ML on December 06, 2007, 01:18:44 PM

Ooops

Forget the parenthesis

I am not using them and it is still not working?

Mark
Title: Re: Sset Move and make basepoint 0,0
Post by: David Hall on December 06, 2007, 01:25:45 PM
what happens if you type INSBASE at the command line?
Title: Re: Sset Move and make basepoint 0,0
Post by: ML on December 06, 2007, 01:30:25 PM

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

Title: Re: Sset Move and make basepoint 0,0
Post by: ML on December 06, 2007, 01:33:43 PM

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.
Title: Re: Sset Move and make basepoint 0,0
Post by: David Hall on December 06, 2007, 01:34:45 PM
It looks like you have to use a variant to set INSBASE
Title: Re: Sset Move and make basepoint 0,0
Post by: David Hall on December 06, 2007, 01:37:11 PM
Code: [Select]
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
Title: Re: Sset Move and make basepoint 0,0
Post by: David Hall on December 06, 2007, 01:38:08 PM
I tested that at 1,1,0 and then 3,1,0 and it worked both times
Title: Re: Sset Move and make basepoint 0,0
Post by: ML on December 06, 2007, 03:15:54 PM

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
Title: Re: Sset Move and make basepoint 0,0
Post by: Jeff_M on December 06, 2007, 03:21:22 PM
As CmdrDuh shows, entering the value for INSBASE as a 3dpoint value it works. Why? Well, look at the definition in help:
Quote
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.
Title: Re: Sset Move and make basepoint 0,0
Post by: ML on December 06, 2007, 03:33:39 PM

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

Title: Re: Sset Move and make basepoint 0,0
Post by: ML on December 06, 2007, 03:37:28 PM

Ok,

I did put that code in and it works great!

Thanks CM - Jeff!

Mark
Title: Re: Sset Move and make basepoint 0,0
Post by: ML on December 06, 2007, 04:02:12 PM

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


Code: [Select]
Dim Basepnt(0 To 2) As Double

Basepnt(0) = 0#: Basepnt(1) = 0#: Basepnt(2) = 0#
ThisDrawing.SetVariable "INSBASE", Basepnt
Title: Re: Sset Move and make basepoint 0,0
Post by: ML on December 06, 2007, 04:06:59 PM

Here is the whole thing if anyone is interested:

Mark

Code: [Select]
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


Title: Re: Sset Move and make basepoint 0,0
Post by: Jeff_M on December 06, 2007, 04:18:44 PM
Code: [Select]
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
Code: [Select]
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.
Title: Re: Sset Move and make basepoint 0,0
Post by: ML on December 06, 2007, 04:22:46 PM

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