Jump to content

How to get the the coordinates of blocks ?


yxl030

Recommended Posts

If the base point of  block is not in the block,how to get the coordinates of it?
As other people will use these diagrams, I can't change the base point.

I wrote a lisp, but there are sometimes it's  correct and sometimes it's not.

 

(defun c:test()
 (setq BasePoint (list -34.80394906 16.72215194)) ;;the Offset coordinates from 0,0 
 (print "select the block1")        ;; this is correct
 (setq ss (ssget '((0 . "INSERT"))))
 (repeat (setq i (sslength ss))
 (setq px (cdr (assoc 10 (entget (ssname ss (setq i (1- i)))))))
 (setq blkAng (cdr (assoc 50 (entget (ssname ss i)))))
 (setq sx (cdr (assoc 41 (entget (ssname ss i)))))
 (setq sy (cdr (assoc 42 (entget (ssname ss i)))))
   (print sx) (print sy)
 (setq p0 (blkCo px blkAng BasePoint sx sy))
 (command "line" p0 '(0 0) "")
 )                                     

 (setq BasePoint (list  -628.69148552 795.40681600))
    (print "select the block2")         ;; this is not  
 (setq ss (ssget '((0 . "INSERT"))))
 (repeat (setq i (sslength ss))
 (setq px (cdr (assoc 10 (entget (ssname ss (setq i (1- i)))))))
 (setq blkAng (cdr (assoc 50 (entget (ssname ss i)))))
 (setq sx (cdr (assoc 41 (entget (ssname ss i)))))
 (setq sy (cdr (assoc 42 (entget (ssname ss i)))))
   (print sx) (print sy)
 (setq p0 (blkCo px blkAng BasePoint sx sy))
 (command "line" p0 '(0 0) "")
 )
 )

(defun blkCo(blkInsert blkAng BasePoint sx sy / p0 px py )
 (setq px (* (car BasePoint) sx))
 (setq py (* (cadr BasePoint) sy))
 (setq p0x (- (car blkInsert) (- (* (cos blkAng) px) (* (sin blkAng) py))))
 (setq p0y (- (cadr blkInsert) (+ (* (cos blkAng) py) (* (sin blkAng) px))))
 (setq p0 (list p0x p0y))
 )

 

And Is there a better way to do this?

Drawing1.dwg

Link to comment
Share on other sites

to set the block base point to 0,0 I would just open the block in the editor then select all, start move command, then select what you want the new base point to be and type 0,0. 

Link to comment
Share on other sites

I'm not sure exactly what you want to do but nentsel may be of help.

 

(defun c:test2 ()
  (princ "\nSelect the block")
  (setq blkdata (nentsel))
  (setq Tmatrix (nth 2 blkdata))
  (setq blk_pt (nth 3 Tmatrix))
  (command "_point" blk_pt)
  (princ "\nBase point = ")
  (princ blk_pt)
  (setq ang (/ (* 180.0 (angle '(0 0 0) (nth 0 Tmatrix))) pi))
  (princ "\nAngle = ")
  (princ ang)
  (setq xscale (distance '(0 0 0) (nth 0 Tmatrix)))
  (setq yscale (distance '(0 0 0) (nth 1 Tmatrix)))
  (princ "\nX scale = ")
  (princ xscale)
  (princ "\nY scale = ")
  (princ yscale)
  (princ)
)

 

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...