- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
hi.
So im trying i make a solid in to a block and for it to choose a poly line that it is linked to, to get its block name from and attributes from.
i have these single part of codes im using to do this by hand:
;------------------------------------------------------------------------------------------------------------------------------------;
;original origin of the code: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/a-lisp-routine-to-create-a-block-from-selected-objectes-and/td-p/11026565
;makes a solid as a block
;choose solid first. then choose the polyline with xdata in. then it copies
;the name from tag "objectid" and makes that the name of the block.
;It adds a number of more if the same block exist with the same name
;edited with help from chatGPT from the original code.
;------------------------------------------------------------------------------------------------------------------------------------;
(defun c:3DBLOCK (/ *error* errmsg :getblockanonymname s p n newname suffix count obj)
(defun *error* (errmsg)
;(setq *error* 'xx:Error)
(if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
(princ (strcat "\nError: " errmsg)))
(setvar 'cmdecho 1)
(princ))
(defun :getblockanonymname ( / d r n)
(while (setq d (tblnext "BLOCK" (null d)))
(if (wcmatch (setq n (cdr (assoc 2 d))) "C$*")
(setq r (cons n r))))
(cond ((car (vl-sort r '>)))
("C$1000")))
(if (and (setq s (ssget))
(setq p '(0 0 0))
(setq n (cdr (assoc "OBJECTID" (get_xd_list (car (entsel))))))
(setvar 'cmdecho 0)
)
(progn
(setq newname n)
(setq suffix "")
(setq count 0)
(while (tblsearch "BLOCK" newname)
(setq count (1+ count))
(setq suffix (strcat "_" (itoa count)))
(setq newname (strcat n suffix)))
(command "_.-BLOCK" newname "_non" p s ""
"_.-INSERT" newname "_s" 1 "_r" 0 "_non" p)
(princ (strcat "\nBlock created '" newname " '"))
)
)
(*error* "end")
);End Defun
And i have this code with help from this forum (user: komondormrex ) :
;------------------------------------------------------------------------------------------------------------------------------------;
;oreign of the code; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-for-adding-attributes-to-a-block-from-xdata/m-p/11991187/highlight/true#M448945
;Copies xdata from a polyline and post it as attributes in to a block that is created from a 3D solid.
;Askes to choose solid first. Then Xdata line.
;------------------------------------------------------------------------------------------------------------------------------------;
(defun get_xd_data ( ename / all_xd_list xd_raw_list xd_paired_list)
(if (setq all_xd_list (assoc -3 (entget ename (list "*"))))
(foreach each_xd (cadr all_xd_list)
(if (and
(= 'list (type each_xd))
(/= "{" (cdr each_xd))
(/= "}" (cdr each_xd))
)
(setq xd_raw_list
(append
xd_raw_list
(list (vl-princ-to-string (cdr each_xd)))
)
)
)
)
)
(repeat (/ (length xd_raw_list) 2)
(setq xd_paired_list (append xd_paired_list (list (cons (car xd_raw_list) (cadr xd_raw_list))))
xd_raw_list (cddr xd_raw_list)
)
)
xd_paired_list
)
i want to link these prosseses by doing this:
activate the program/lisp.
fence or/and single choose solids.
it finds the linked polyline and gets its name from that line, makes the block, then starts the attribute adding from xdata from that same polyline.
i have posted an example drawing.
i need it to ignore adding the polyline in to the block.
Also. in the example i have added a weld line that we use that also reads as a polyline and is linked to the solid. But its in a different layer.
i have made a "finished" product and colored it red. But the code do NOT have to color anything as i only did it to show difference between the two.
is this possible to do?
Solved! Go to Solution.