Insert block on each selected point

Insert block on each selected point

Anonymous
Not applicable
3,741 Views
8 Replies
Message 1 of 9

Insert block on each selected point

Anonymous
Not applicable

I'm new to LISP and I need a routine which inserts a block I have onto each individual that has been selected point selected.

Any ideas on how I could achieve this?

0 Likes
Accepted solutions (1)
3,742 Views
8 Replies
Replies (8)
Message 2 of 9

Kent1Cooper
Consultant
Consultant

Welcome to these Forums!

 

That sounds simple enough, but a question:  By "point selected," do you mean a location picked on, as when picking "points" while drawing Lines, etc., or an actual Point entity that the User would select in object-selection fashion?

Kent Cooper, AIA
0 Likes
Message 3 of 9

Anonymous
Not applicable

A point such as a node if that is what you mean by Point entity

0 Likes
Message 4 of 9

Kent1Cooper
Consultant
Consultant

In simplest terms, something like this [untested]:

(defun C:BAP (/ ss n); = Blocks At Points

  (prompt "\nTo place YourBlockName Block(s) at selected Point object(s),")

  (if (setq ss (ssget '((0 . "POINT")))); will supply its own Select objects prompt

    (repeat (setq n (sslength ss)); then

      (command

        "_.insert" "YourBlockName"

        "_none" (cdr (assoc 10 (entget (ssname ss (setq n (1- n))))))

        "" "" ""

      ); command

    ); repeat

    (prompt "\nNo Point(s) selected."); else

  ); if

  (princ)

); defun

 

That's at default scale factors of 1 for a Block not defined to be only uniformly scaled, rotation of 0, assuming a Block without Attributes.  Lots of enhancements are possible [Layer control, Undo begin/end wrapping, command-echo suppression, error handling to reset those in case something goes wrong, scale factors calculated from drawing scale, notification to the User of how many were Inserted, remembering the Block name and offering it as a default in later use, etc., etc.].

Kent Cooper, AIA
0 Likes
Message 5 of 9

_Tharwat
Advisor
Advisor
Accepted solution

Try this:

 

(defun c:Test ( / BlockName ss sn)
  ;; Tharwat - Date: 28.June.2016 ;;
  (setq BlockNAme "ABC") ;; Replace ABC with your Block Name and be sure it is not Attributed Block.
  (if (and (or (tblsearch "BLOCK" BlockName)
               (progn
                 (princ (strcat "\nBlock name <" BlockName "> is not found in this drawing !")) nil)
               )
           (princ (strcat "\nSelect points to place the block name < " BlockName " > at their insertion point :"))
           (setq ss (ssget '((0 . "POINT"))))
           )
    (while (setq sn (ssname ss 0))
      (entmake (list '(0 . "INSERT") (cons 2 BlockName) (assoc 10 (entget sn))))
      (ssdel sn ss)
      )
    )
  (princ)
  )
0 Likes
Message 6 of 9

rravgeotec
Contributor
Contributor

is possible to get block in respective point's layer as well? in AutoCAD LT?

0 Likes
Message 7 of 9

ВeekeeCZ
Consultant
Consultant

Sure - if you are versed enough with Excel or another program to work with a text file. You can use the LIST command, export info of points inc. coords and layers. Then create a SCRIPT for each point. Something like this:

-layer set "mypointlayer" -insert blockname 1 0 x,y    ...See more info here HERE 

 

All the above-suggested solutions are using AutoLISP - not supported in LT.

 
0 Likes
Message 8 of 9

Sea-Haven
Mentor
Mentor

I think this is supported in LT LOGFILEON when you do the list it will write to a logfile, you need to press enter all the time depending on how many you select. Then do LOGFILEOFF to stop recording. you can then load into excel I would look at a macro to read only the X Y values line, then can do something to make a suitable output.

 

The other cad programs support Lisp and do more than LT worth considering. Just work out for 1 function that you do a day and how long to do compare with say 3 seconds. How much did you save in 1 week ? I look at 30 minutes now 40 seconds. Multiple every day.

0 Likes
Message 9 of 9

Anonymous
Not applicable

I am asking for help with that similar to that. I use 2 separate lisp for this job. Someone to adjust the distance and to make the array according to the distance. In between there, you need to select the object to the Array.

 

Can you add to select objects by combining these two lisps?

 

(defun c:ds (/ d a b)
(if (setq d (getdist "\nDist:"))
(alert (strcat "X= " (rtos (setq a (/ d 100)) 2 2)
"\nY= " (rtos (setq b (1+ (fix a))) 2 2) "\nZ= " (rtos (/ (- d 10) b) 2 2)))
) (princ)
)

 

 

 

(defun c:tt (/ ss p1 p2 num ang dst dst2)
(if (and (setq ss (ssget "_:L"))
(setq p1 (getpoint "\nSpecify first point: "))
(setq p2 (getpoint p1 "\nSpecify next point: "))
(progn (initget 6) (setq num (getint "\nSpecify number of copies: ")))
)
(progn
(setq ang (angle p1 p2)
dst (distance p1 p2)
dst2 0.
)
(repeat num (command "_.copy" ss "" "_non" p1 "_non" (polar p1 ang (setq dst2 (+ dst dst2)))))
)
)
(princ)
)

 

0 Likes