Jump to content
jmsimpson

LISP for changing block references to circles

Recommended Posts

jmsimpson

I have over a thousand block reference points that I have imported into AutoCAD. I would like to convert these block reference "crosshairs" into circles. I want the diameter of these circles to correspond with the elevation numbers from the data set. If you're wondering why I want this, I am trying to make a map of trees in a plot and the diameter is one of the crucial bits of information I want displayed for every tree. Inputing the data in PENZD style limits the amount of information displayed and, since I only need a 2D map, the elevation represents the diameters.

 

I have a lisp code for converting points to circles but I haven't found a way to convert block reference data to circles. If anyone could write that code or instruct me on how this can be accomplished, I would greatly appreciate it. Thanks!

Share this post


Link to post
Share on other sites
vnanhvu

YOU CAN TEST WITH MY LISP

(defun c:GGG ()  (defun mid (ent / p1 p2)    (vla-getboundingbox (vlax-ename->vla-object ent) 'p1 'p2)    (setq p1 (vlax-safearray->list p1)	  p2 (vlax-safearray->list p2)	  pt (mapcar '+ p1 p2)	  pt (mapcar '* pt '(0.5 0.5 0.5))    )    pt  )  (setq src (car (entsel "\nDoi tuong can di chuyen: ")))  (redraw src 3)  (setq des (car (entsel "\nDoi tuong dich: ")))  (redraw src 4)  (setq oldos (getvar "osmode"))  (setvar "osmode" 0)  (command ".move" src "" (mid src) (mid des))  (setvar "osmode" oldos)  (princ))(vl-load-com)

Share this post


Link to post
Share on other sites
Lee Mac

Since I'm feeling generous today :)

 

(defun c:test ( / el i pt ss x )

 (if (setq ss (ssget "_:L" '((0 . "INSERT"))))
   (repeat (setq i (sslength ss))
     (setq el (entget (ssname ss (setq i (1- i))))
           pt (cdr (assoc 10 el))
     )
     (if
       (entmakex
         (append
           (list
             (cons 0 "CIRCLE")
             (list 10 (car pt) (cadr pt) 0.)
             (cons 40 (if (equal 0.0 (last pt) 1e- 1.0 (abs (/ (last pt) 2.))))
           )
           (apply 'append
             (mapcar
              '(lambda ( x ) (if (assoc x el) (list (assoc x el))))
              '(8 6 39 48 62 210)
             )
           )
         )
       )
       (entdel (cdr (assoc -1 el)))
     )
   )
 )
 (princ)
)

 

EDIT: Just noticed you want a 2D representation, code updated.

Share this post


Link to post
Share on other sites
jmsimpson

So perhaps it's the operator but I was not able to get either code to work. I copied them into vlisp and saved them as lisps then ran them by apploading them. The shapes of the crosshairs did not change. Am I inputing the code incorrectly? Thanks for taking your time to write the codes, v & leemac

Share this post


Link to post
Share on other sites
Lee Mac

What happens when you select your blocks using my program? Do you get an error?

Share this post


Link to post
Share on other sites
jmsimpson

The first time, it sent all of the points and other files I have in the workspace into a template. That was all that happened. I've tried it a few times afterwards and nothing happened.

Share this post


Link to post
Share on other sites
Lee Mac

Files? Template? What are you talking about? It should be a case of selecting your blocks and converting them to circles - its a very simple code, there really isn't too much that can go wrong.

Share this post


Link to post
Share on other sites
jmsimpson

I selected the blocks, input the code into the command and it didn't work. From there, I tried making it work in other ways. I've probably done something wrong but I have barely used this software.

Share this post


Link to post
Share on other sites
Lee Mac

When you say "it didn't work", what happened? What was printed at the command line? I'm slightly perplexed since I quickly tested the code prior to posting and all worked fine. Is it working for anyone else?

Share this post


Link to post
Share on other sites
jmsimpson

It says "C:TEST"

Share this post


Link to post
Share on other sites
Lee Mac

After loading are you issuing the command 'Test' to run the program?

 

If you are new to LISP, read the 'How to use code in this Archive' thread in the application archive forum. Or there is a tutorial on my site (link in my sig). I would link you to the threads but I'm posting from my mobile.

Share this post


Link to post
Share on other sites
jmsimpson

Lee Mac,

 

I got it to work. Thanks for your help. My last comment should be evidence as to how much I know about code and AutoCAD.

 

Much Gracious

JMS

Share this post


Link to post
Share on other sites
Lee Mac

Not a problem JMS, I'm glad it works for you now.

 

After reading back over my other replies, I apologise if I sounded frustrated - I wasn't aware of your inexperience with LISP.

 

Regards,

 

Lee

Share this post


Link to post
Share on other sites
jmsimpson
Since I'm feeling generous today :)

 

(defun c:test ( / el i pt ss x )

 (if (setq ss (ssget "_:L" '((0 . "INSERT"))))
   (repeat (setq i (sslength ss))
     (setq el (entget (ssname ss (setq i (1- i))))
           pt (cdr (assoc 10 el))
     )
     (if
       (entmakex
         (append
           (list
             (cons 0 "CIRCLE")
             (list 10 (car pt) (cadr pt) 0.)
             (cons 40 (if (equal 0.0 (last pt) 1e- 1.0 (abs (/ (last pt) 2.))))
           )
           (apply 'append
             (mapcar
              '(lambda ( x ) (if (assoc x el) (list (assoc x el))))
              '(8 6 39 48 62 210)
             )
           )
         )
       )
       (entdel (cdr (assoc -1 el)))
     )
   )
 )
 (princ)
)

 

EDIT: Just noticed you want a 2D representation, code updated.

___________________________________________________________________

 

This code works well but I would like to display the point, elevation and description information. I am scouring AutoCad now looking for a way to display the info but if anyone has advice on how to do that, it would be much appreciated

 

JMS

Share this post


Link to post
Share on other sites
troggarf

Works fine Lee

~Greg

Share this post


Link to post
Share on other sites
Lee Mac

Thanks for testing Greg :)

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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