lisp to converts alot of objects to block in one time

lisp to converts alot of objects to block in one time

pink_floid23
Enthusiast Enthusiast
4,337 Views
27 Replies
Message 1 of 28

lisp to converts alot of objects to block in one time

pink_floid23
Enthusiast
Enthusiast

hi

i have this lisp convert object to block , but it make one by one , i need it fix to convert a lot of objects in one time to block ,(choose block by click on block or choose from list or insert be type new name ) 

0 Likes
4,338 Views
27 Replies
Replies (27)
Message 2 of 28

ВeekeeCZ
Consultant
Consultant

So you don't care about insertion points (would be 0,0) neither block names... (some unique whatever).

BTW I can't believe that there is not plenty on the web already. I think even I wrote some. 

0 Likes
Message 3 of 28

pink_floid23
Enthusiast
Enthusiast

i searched and found the lisp i attached in the post .it work one by one

i want modify it to work in a lot of objects in one time

0 Likes
Message 4 of 28

ВeekeeCZ
Consultant
Consultant

Ok, I see, it makes sense. I wouldn't do that any different.

 

(defun c:Blockitinnotime (/ s o e n m x b)

  (if (setq s (ssget '((-4 . "<NOT") (0 . "VIEWPORT,RAY,XLINE,INSERT") (-4 . "NOT>"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    n (cdr (assoc 0 (entget e))))
      (setq x 1000)
      (while (tblsearch "BLOCK" (setq m (strcat n "_" (itoa (setq x (1+ x)))))))
      (entmake (list '(0 . "BLOCK") '(10 0 0 0) (cons 2 m) '(70 . 0)))
      (entmake (entget e))
      (and (= 1 (cdr (assoc 66 (entget (setq b e)))))
	   (while (not (= "SEQEND" (cdr (assoc 0 (entget (setq b (entnext b)))))))
	     (entmake (entget b)))
	   (entmake (entget b)))
      (entdel e)
      (entmake '((0 . "ENDBLK") (8 . "0")))
      (entmake (list '(0 . "INSERT") (cons 2 m) '(10 0 0 0)))))
  (princ)
  )

 

Message 5 of 28

Moshe-A
Mentor
Mentor

@pink_floid23 ,

 


@pink_floid23 wrote:

hi

i have this lisp convert object to block , but it make one by one , i need it fix to convert a lot of objects in one time to block ,(choose block by click on block or choose from list or insert be type new name ) 


explain what do you mean one by one?

i tried this lisp and it let you select as many objects as you like and turn them to block.

 

moshe

 

0 Likes
Message 6 of 28

pink_floid23
Enthusiast
Enthusiast

it convert but make every block with different name , so i need 2 issue :

1) convert to the same name , or name i enter it .

2) when try replace the block with block attribute to make changes on work (i convert polyline to blocks) , it disappear .

i will attach the lisp and dwg

 

0 Likes
Message 7 of 28

pink_floid23
Enthusiast
Enthusiast

thanks for you reply ,

i mean that make all of them block , i need every one is single block with the same name .not different blocks names.

cause i work on sewer network projects , and want convert a lot of polyline ,circle..etc to blocks attribute to can add value to each one of them

 

0 Likes
Message 8 of 28

pendean
Community Legend
Community Legend
You cannot create many blocks with one single name: AutoCAD will not allow it. Sorry. No lisp will overcome that limitation.
0 Likes
Message 9 of 28

pink_floid23
Enthusiast
Enthusiast

NO AUTOCAD CAN MAKE IT , I WILL ATTACH LISP CONVERT CIRCLE TO BLOCK , CONVERT MANY CIRCLES TO THE SAME BLOCK NAME ,

FOR EXAMPLE CHOOSE BLOCK NAME (MH) IT CONVERT ALL CIRCLES YOU SELECT TO BLOCK ,EVERY ONE TO BLOCK WITH THE SAME NAME TO ALL

0 Likes
Message 10 of 28

Kent1Cooper
Consultant
Consultant

I'm not fluent with dynamic Blocks, but could the linear ones could be a same-named dynamic Block with a length variable?  Could the circular one be included in the same Block name, using visibility states?

Kent Cooper, AIA
0 Likes
Message 11 of 28

SeeMSixty7
Advisor
Advisor

It sounds like you want to convert all the similar symbols on the drawing to one block name and apply it to all the occurrences of that symbol(s). You can utilize the LISP routine you have, just tweak it to take the single selection of the entities, Then add some function for when you do that to find all the circles that match the parameters of that selected object, then find all those circles then select objects around that circle that match the previous selection, erase those and drop in the block to match what was there. If there are attributes to consider with varying text values associated with the symbols for that new location you would want to place the block and then populate the attributes with the values from the text of the associate entities previously there.

 

You can see there are a lot of variables and information that someone will need to help you with this exercise. 

 

Good luck,

 

 

 

0 Likes
Message 12 of 28

pink_floid23
Enthusiast
Enthusiast

thanks for your reply

0 Likes
Message 13 of 28

pink_floid23
Enthusiast
Enthusiast

thanks for your reply 

 

0 Likes
Message 14 of 28

EiPM_Xavi
Participant
Participant

Wow! it's an amzing lisp.

The results to apply this lisp, create blocks stored in the current layer of the DWG file.

I have a lot of 3D entities, stored in diffent layers: how to adapt this lisp, in order to create blocks with the same layer of the "original" 3D entity?

For example:

- Scenario of a DWG: 2 solids in a "Layer_A", 2 solids in a "Layer_B", 2 solids in a "Layer_C"

- For each solid, the block should be in the layer of the entity, and the name of the block should be with the name of the layer. Is it possible?

I attach an image and a zip file with 3 dwg files (Original, result with the lisp, expected result)

Thanks a lot!

Xcoll

 

_Results_comparative.png

0 Likes
Message 15 of 28

ВeekeeCZ
Consultant
Consultant

Sure, that is quite simple to do.

 


@EiPM_Xavi wrote:

... I attach an image and a zip file with 3 dwg files (Original, result with the lisp, expected result) ...


Very nice, I wish everyone is so thorough!

 

(defun c:Blockitinnotime (/ :AddLeadingZeros s o e n m x b l)

    (defun :AddLeadingZeros (a d / b) ;add zeros to 'd' many digits  ;a string
    (strcat (substr "000000000" 1 (if (>= d (setq b (strlen (itoa (fix (atof a)))))) (- d b) 0)) a))

  (if (setq s (ssget '((-4 . "<NOT") (0 . "VIEWPORT,RAY,XLINE,INSERT") (-4 . "NOT>"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    n (cdr (assoc 8 (entget e)))
	    l (assoc 8 (entget e)))
      (setq x 0)
      (while (tblsearch "BLOCK" (setq m (strcat n "_" (:AddLeadingZeros (itoa (setq x (1+ x))) 2)))))
      (entmake (list '(0 . "BLOCK") '(10 0 0 0) (cons 2 m) '(70 . 0)))
      (entmake (entget e))
      (and (= 1 (cdr (assoc 66 (entget (setq b e)))))
	   (while (not (= "SEQEND" (cdr (assoc 0 (entget (setq b (entnext b)))))))
	     (entmake (entget b)))
	   (entmake (entget b)))
      (entdel e)
      (entmake '((0 . "ENDBLK") (8 . "0")))
      (entmake (list '(0 . "INSERT") (cons 2 m) l '(10 0 0 0)))))
  (princ)
  )

 

Message 16 of 28

EiPM_Xavi
Participant
Participant

Thanks a lot for the super-fast answer!

Mmmm... I tested this version of the lisp, and the result is the same like in the lisp shared in the start of the thread.

I share an Image:

- In the left side -> Result to use the new lisp

- In the right side -> Expected result

Kind regards,

XColl

_Results_comparative.png

0 Likes
Message 17 of 28

ВeekeeCZ
Consultant
Consultant

I've realized that and updated the code a few mins ago... check again.

Message 18 of 28

EiPM_Xavi
Participant
Participant

Wooooow! it's really amazing! thanks a lot!

Mmmm... only a last thing about the expected results, is it possible that the block can be in the same layer of the original entity?

I share an image.

Thanks a lot for yous super-support!

Xcoll

Resutls_second_version.png

0 Likes
Message 19 of 28

ВeekeeCZ
Consultant
Consultant

Not sure how that happened... that line was there before the update. 

So now updated again. Hopefully, no line missing this time.

Message 20 of 28

EiPM_Xavi
Participant
Participant

Wow! thanks a lot for your suuuuuper fast answer! 😄

Mmmmm... I just tested the last version of the Lisp, but in the results, the blocks hasn't the layer of the original entity (as it's shown in the screenshot of my last shared image).

Thanks a lot!

XColl

0 Likes