Jump to content

Move point


Scoutr4

Recommended Posts

Hi everyone,

Example code;
(command "move" ent1 "" "_non" "0,0,0" "_non" "500,0,0")

I trying set "500,0,0"  with question but give error.

Because I can use 1000 or more value. 

Which question can set move point? 

Link to comment
Share on other sites

I am not sure of the problem, if I copy and paste your code directly into the command line it will move an entity, ent1, 500, as it should

 

Is there more to tis code that might be causing a problem before or after, and does your CAD give any errors in the command line?

Link to comment
Share on other sites

Okay . I'm editing a block diagram for project . I combined 2 lisp files and created a lisp that works for me.

Original lisp files ; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-move-multiple-text-to-line/td-p/3480202

 https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/move-blocks-to-insertion-point-of-another-block/td-p/8915522

(defun c:dex ( / osm ss a_pt cnt ent i_pt)
  (setq osm (getvar 'osmode))
   (prompt "\nSelect Blocks to Align (except first block): ")
   (setq ss (ssget '((0 . "INSERT"))))
    (prompt "\nFirst block : ")
    (setq ss1 (ssget '((0 . "INSERT"))))
    (setvar 'osmode 64)
    (repeat (setq cnt (sslength ss))
      (setq ent (ssname ss (setq cnt (1- cnt)))
            i_pt (cdr (assoc 10 (entget ent)))
      );end_setq
      (setq cnt1 (sslength ss1))
      (setq ent1 (ssname ss1 (setq cnt1 (1- cnt1)))
       a_pt (cdr (assoc 10 (entget ent1))))
      (setvar 'osmode 0)
      (vl-cmdf "move" ent "" i_pt a_pt)
      (command "move" ent1 "" "_non" "0,0,0" "_non" "500,0,0")
      (setvar 'osmode 64)
    );end_repeat
    (setq ss nil)
    (setq ss1 nil)
  (setvar 'osmode osm)
  (setvar "cmdecho" 0)
  (princ)
);end_defun
(Defun c:xs  (/ li txts e)
      (if
            (and (princ "\nSelect Line : ")
                 (setq li (ssget "_+.:S:E" '((0 . "*LINE"))))
                 (princ "\nSelect Blocks : ")
                 (setq txts (ssget '((0 . "INSERT")))))
                 (repeat (sslength txts)
                       (vla-move
                             (setq e (vlax-ename->vla-object
                                           (ssname txts 0)))
                             (vla-get-insertionpoint e)
                             (vlax-3d-point
                                   (vlax-curve-getclosestpointto
                                         (ssname li 0)
                                         (vlax-get e 'insertionpoint)))
                             )
                       (ssdel (ssname txts 0) txts)
                       )
                 )
      (setvar "cmdecho" 0)
      (princ)
(c:dex)
)

Example ; https://imgur.com/a/fnJU7qW

(command "move" ent1 "" "_non" "0,0,0" "_non" "500,0,0") ;instead of this code
I want to edit this code like this 
(setq n (getpoint (strcat "\nDistance :")) ;it gives error like this
(command "move" ent1 "" "_non" "0,0,0" "_non" n)

 

Link to comment
Share on other sites

;;----------------------------------------------------------------------;;
;; SPACE BLOCKS BY DISTANCE
(defun c:dex (/ ss fblk dist pt1 line ang pt)
  (prompt "\nSelect Blocks to Align: ")
  (setq ss (ssget '((0 . "INSERT"))))
  (if (setq fblk (car (entsel "\nSelect First Block : ")))
    (ssdel fblk ss)
  )
  (setq dist (getdist "\nSpacing Distance :"))
  (setq pt1 (cdr (assoc 10 (entget fblk))))
  (setq ang (getangle "\nSpace Blocks on angle : "))  
  (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
    (setq ent (entget ent))
    (setq pt (polar pt1 ang dist))
    (entmod (subst (cons 10 pt) (assoc 10 ent) ent))
    (setq pt1 pt)
  )
  (princ)
)
;;----------------------------------------------------------------------;;
;; MOVE BLOCKS TO LINE
(defun c:xs (/ SSBLK blk pt1 pt2)
  (princ "\nSelect Blocks : ")
  (setq SSBLK (ssget '((0 . "INSERT"))))
  (setq line (car (entsel "\nSelect Line : ")))
  (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SSBLK)))
    (setq pt1 (cdr (assoc 10 (setq ent (entget ent)))))
    (setq pt2 (vlax-curve-getclosestpointto (vlax-ename->vla-object line) pt1))
    (entmod (subst (cons 10 pt2) (assoc 10 ent) ent))
  )
  (C:dex)
  (princ)
)

 

--edit

 

updated code if line wasn't horizontal dex wasn't correct

Edited by mhupp
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

When select line give this error ; 

Select Line : ; error: lisp value has no coercion to VARIANT with this type:  (17211.2 6979.47 0.0)

 

Link to comment
Share on other sites

Changed to entmod dont have to mess with osmode see if line select gives you a problem.

 

 

--edit

Dex is to space them off the line angle?

Edited by mhupp
Link to comment
Share on other sites

I tried this now updated code . It works smoothly and you added an angle question, that is nice. 

14 minutes ago, mhupp said:

Dex is to space them off the line angle?

If I specify an angle like this? i think the code works with correct logic

image.png

Edited by Scoutr4
Link to comment
Share on other sites

I know how you like to rotate things and break my code @Scoutr4

 

Capture.thumb.PNG.ba66606e52f3ee148f9dca720fa7fe34.PNG

 

so if you use 0 angle it would be the 3rd from the top

last one is using the endpoints of line when prompt for angle

 

if they are always going to be horizontal lines. remove the getangle and update the pt line with

(setq pt (mapcar '+ pt1 (list dist 0 0))

 

Edited by mhupp
  • Like 1
Link to comment
Share on other sites

31 minutes ago, mhupp said:

I know how you like to rotate things and break my code @Scoutr4

 

True !! 🤓

i like to do break codes nowadays and this code took its place in my lisp library 👍

Edited by Scoutr4
  • Like 1
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...