Jump to content

Problems with align-lisp


Randolph

Recommended Posts

Hi,

 

I had this topic before, and a collegue here helped me along. It is about sort of an align functionality. Unfortunately, the lisp has a bug which doesn't always show. Let me explain:

 

Say I have a table in a ground plan. Its x,y-position is right, but in 3D, it hovers above the ground. I want to put on the floor without moving it in x,y. I enter TZP (translate along z using points), select the table, click the table leg base and then any corner of the room. The table will drop to the floor.

 

Now I need the same table on the 2nd floor. I enter DZP (duplicate along z using points), select the table, click the table leg base again and then any point on the level of the 2nd floor.

 

The clue is that I don't need any 2 points which are exactly above each other. This is the code:

 

(defun c:TZP ( / a b c s)
 (princ "Select objects: ")
 (setq s (ssget)
   a (getpoint "\nSelect item base point: ")
   b (getpoint "\nSelect target point: ")
   c (list (car a) (cadr a) (caddr b)))
 (vl-cmdf "move" s "" a c)
 )

Same goes with copy resp the other axis. I find the code quite elegant, as far as an architect can judge.

 

But for whatever reason, from time to time the "table" will move in x,y-ways in an unpredictable manner, but most often close to the required position. As things get worse the longer I work with this command, could it be that this has to do with variables beeing assigned values which are not cleared? Or with the object snap not beeing deactivated?

 

Thanx for your help in advance!

Link to comment
Share on other sites

I mean you can use the "align" command directly in Autocad and there is no need for re-writing a routine , unless you have

any other special reasons to do that .

 

Tharwat

Link to comment
Share on other sites

ReMark: Of course I do move the UCS. I just wanted to express that I usually set it to "world" before moving or copying vertically or horzontally.

 

Tharwat: Because the align command works quite differently to what I need. Maybe I was misunderstandable using that expression. What I need is just: move an object from the height of point 1 to the height point 2 without else moving, rotating or scaling it.

Link to comment
Share on other sites

Tharwat: I know. That's what I usually do: measure the distance, copy the z-value, call my command tz (move z-ways) and paste the z-value. But that's tiresome on the long term.

 

It would be so helpful if anybody found the bug in above routine, as I didn't/couldn't.

Link to comment
Share on other sites

Seems that you want to move some entities to a new elevation - for sure you can use OSNAP filters to achive this.

Regarding the inconsistent behaviour of the routine I suppose that is from having OSNAP mode activated while using the routine; please find below some suggested corrections.

 

 
(defun c:TZP ( / [color=red]OldOsm[/color] a b c s)
[color=red](setq OldOsm (getvar "OSMODE"))[/color]
[color=red](princ "Select objects: ")[/color]
[color=red](if (and[/color] (setq s (ssget))
         (setq a (getpoint "\nSelect item base point: "))
         (setq b (getpoint "\nSelect target point: "))[color=red])[/color]
[color=red](progn[/color]
  (setq c (list (car a) (cadr a) (caddr b)))
  [color=red](setvar "OSMODE" 0)[/color]
  (vl-cmdf "move" s "" a c)
[color=red])[/color]
[color=red])[/color]

[color=red](setvar "OSMODE" OldOsm)[/color]
[color=red](princ)[/color]
)

 

 

Regards,

Mircea

Edited by MSasu
fixed a syntax error
Link to comment
Share on other sites

Hi Mircea,

 

thanx, sorry I didn't see you reply before my last posting. I'll try it yor way; OSNAP is also my suspect.

 

Ralph

Link to comment
Share on other sites

Hi Mircea,

 

basically, your code works. Only that it deactivates the osnap before choosing the points, which is not so good. Also, it seems that it does not reactivate the osnap. It seems that your code asks the osnap status and shall regenerate it afterwards, but I didn't full understand how. Thus I changed it to my more primitive way, and now it seems to work:

 

(defun c:TZP ( / OldOsm a b c s)
(princ "Select objects: ")
(if (and (setq s (ssget))
         (setq a (getpoint "\nSelect item base point: "))
         (setq b (getpoint "\nSelect target point: ")))
 (progn
  (setq c (list (car a) (cadr a) (caddr b)))
  (COMMAND "_OSNAP" "")

  (vl-cmdf "_move" s "" a c)
 )
)
(COMMAND "_OSNAP" "_END,_INT,_MID,_CEN,_INS,_PER")
(princ)
)

Link to comment
Share on other sites

Seems that you missed to copy some lines from my example - I added those to your code along with comments of each action. The OSNAP mode is stored in OSMODE system variable: 1st, the current setting is stored into a local variable; 2nd, the mode is disabled to don't interfere with the command call; 3rd, the previously stored state is restored.

Please remember that it is a very good programming practice to restore user's environment after your routine is done.

 

(defun c:TZP ( / OldOsm a b c s)
[color=blue] (setq OldOsm (getvar "OSMODE"))   ;retain current state of OSNAP mode[/color]
(princ "Select objects: ")
(if (and (setq s (ssget))
         (setq a (getpoint "\nSelect item base point: "))
         (setq b (getpoint "\nSelect target point: ")))
 (progn
  (setq c (list (car a) (cadr a) (caddr b)))
  [color=blue];[/color](COMMAND "_OSNAP" "")
  [color=blue](setvar "OSMODE" 0)             ;disable OSNAP mode
[/color]   (vl-cmdf "_move" s "" a c)
 )
)
[color=blue] (setvar "OSMODE" OldOsm)          ;restore previous state of OSNAP mode[/color]
[color=blue];[/color](COMMAND "_OSNAP" "_END,_INT,_MID,_CEN,_INS,_PER")
(princ)
)

 

 

Regards,

Mircea

Link to comment
Share on other sites

Don't apologize, you helped me a lot! I agree that the method of restoring the previous status is more elegant. But on the other side, I have lots of commands with (COMMAND "_OSNAP" "_END,_INT,_MID,_CEN,_PER,_INS"). This is because I'm no programmer, and copied my acad.lsp together from many places.

 

By the way: would you mind lokking at my other thread:

Rotate around x,y,z-axis

 

 

Somhow, it seems to be a problem there.

Link to comment
Share on other sites

If decide to switch to usage of system variables instead of command call, you can set the current mode by summate the values for each desired mode:

 

None                     0
Endpoint                 1
Midpoint                 2
Center                   4
Node                     8
Quadrant                16
Intersection            32
Insertion               64
Perpendicular          128
Tangent                256
Nearest                512
Apparent Intersection 2048
Extension             4096
Parallel              8192

 

For example: Endpoint + Midpoint + Quadrant: OSMODE = 1 + 2 + 16 = 19

 

Regards,

Mircea

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...