Jump to content

Recommended Posts

Posted

Hello everyone, I've made this function to add block with attributes to drawing, but it's not working, and when I call -insert, i get that the block references itself, but how when it's not even in block editor list?

;makes a block and inserts to drawing
(defun cssabl_blk (pt station height /)
    (setvar "CMDECHO" 0)
    (if	(not (tblsearch "BLOCK" "CSSABL")) ;_ _not
	(progn
	    (entmake
		(list
		    (cons 0 "BLOCK")
		    (cons 2 "CSSABL")
		    (cons 70 2)
		    (cons 10 '(0. 0. 0.))
		) ;_ _list
	    ) ;_ _entmake
	    (entmake
		(list
		    (cons 0 "POINT")
		    (cons 8 "0")
		    (cons 10 '(0. 0. 0.))
		) ;_ _list
	    ) ;_ _entmake
	    (entmake
		(list
		    (cons 0 "ATTDEF")
		    (cons 8 "0")
		    (cons 10 '(0.0 0.0 0.0))
		    (cons 70 0)
		    (cons 1 "")
		    (cons 2 "STATION")
		    (cons 40 2.0)
		) ;_ _list
	    ) ;_ _entmake
	    (entmake
		(list
		    (cons 0 "ATTDEF")
		    (cons 8 "0")
		    (cons 10 '(0.0 0.0 0.0))
		    (cons 70 0)
		    (cons 1 "")
		    (cons 2 "HEIGHT")
		    (cons 40 2.0)
		) ;_ _list
	    ) ;_ _entmake
	    (entmake
		(list
		    (cons 0 "ENDBLK")
		    (cons 8 "0")
		) ;_ _list
	    ) ;_ _entmake
	) ;_ _progn
    ) ;_ _if
    (entmake
	(list
	    (cons 0 "INSERT")
	    (cons 2 "CSSABL")
	    (cons 10 pt)
	    (cons 66 1)
	) ;_ _list
    ) ;_ _entmake
    (entmake
	(list
	    (cons 0 "ATTRIB")
	    (cons 10 pt)
	    (cons 1 station)
	    (cons 2 "STATION")
	    (cons 40 2.0)
	    (cons 70 0)
	) ;_ _list
	)
    (entmake
	(list
	    (cons 0 "ATTRIB")
	    (cons 10 pt)
	    (cons 1 height)
	    (cons 2 "HEIGHT")
	    (cons 40 2.0)
	    (cons 70 0)
	) ;_ _list
    ) ;_ _entmake
    (entmake
	(list
	    (cons 0 "SEQEND")
	) ;_ _list
    ) ;_ _entmake
);defun

 

Posted

You need to add dxf group code 3 when creating block, its for prompt i think.
Here is edited code I just copied string of dxf code 2, works for me
 

;;; Copied to window at 2:06 PM 6/12/24

(defun cssabl_blk (pt station height /)
    (setvar "CMDECHO" 0)
    (if	(not (tblsearch "BLOCK" "CSSABL")) ;_ _not
	(progn
	    (entmake
		(list
		    (cons 0 "BLOCK")
		    (cons 2 "CSSABL")
		    (cons 70 2)
		    (cons 10 '(0. 0. 0.))
		) ;_ _list
	    ) ;_ _entmake
	    (entmake
		(list
		    (cons 0 "POINT")
		    (cons 8 "0")
		    (cons 10 '(0. 0. 0.))
		) ;_ _list
	    ) ;_ _entmake
	    (entmake
		(list
		    (cons 0 "ATTDEF")
		    (cons 8 "0")
		    (cons 10 '(0.0 0.0 0.0))
		    (cons 70 0)
		    (cons 1 "")
		    (cons 2 "STATION")
		    (cons 3 "STATION")
		    (cons 40 2.0)
		) ;_ _list
	    ) ;_ _entmake
	    (entmake
		(list
		    (cons 0 "ATTDEF")
		    (cons 8 "0")
		    (cons 10 '(0.0 0.0 0.0))
		    (cons 70 0)
		    (cons 1 "")
		    (cons 2 "HEIGHT")
		    (cons 3 "HEIGHT")
		    (cons 40 2.0)
		) ;_ _list
	    ) ;_ _entmake
	    (entmake
		(list
		    (cons 0 "ENDBLK")
		    (cons 8 "0")
		) ;_ _list
	    ) ;_ _entmake
	) ;_ _progn
    ) ;_ _if
    (entmake
	(list
	    (cons 0 "INSERT")
	    (cons 2 "CSSABL")
	    (cons 10 pt)
	    (cons 66 1)
	) ;_ _list
    ) ;_ _entmake
    (entmake
	(list
	    (cons 0 "ATTRIB")
	    (cons 10 pt)
	    (cons 1 station)
	    (cons 2 "STATION")
	    (cons 40 2.0)
	    (cons 70 0)
	) ;_ _list
	)
    (entmake
	(list
	    (cons 0 "ATTRIB")
	    (cons 10 pt)
	    (cons 1 height)
	    (cons 2 "HEIGHT")
	    (cons 40 2.0)
	    (cons 70 0)
	) ;_ _list
    ) ;_ _entmake
    (entmake
	(list
	    (cons 0 "SEQEND")
	) ;_ _list
    ) ;_ _entmake
);defun

;;; End of text

 

  • Like 1
Posted

For the attributes try this format:

 

(entmakex (list
  (cons 0 "ATTDEF")
  (cons 100 "AcDbEntity")
  (cons 8 "0")
  (cons 100 "AcDbText")
  (cons 10 '(0.0 0.0 0.0) )
  (cons 40 2)
  (cons 1 "Default")
  (cons 100 "AcDbAttributeDefinition")
  (cons 3 "Prompt")
  (cons 2 "TAG")
  (cons 70 0)
))

 

and also I think for attributes put in an attsync when the block is inserted

  • Like 1
Posted (edited)

thank you, haven't found anywhere that this is obligatory, just wondering what it's for?

also, maybe someone knows how to make theee atts invisible?

Edited by Tomislav
Posted (edited)
4 minutes ago, Tomislav said:

thank you, haven't found anywhere that this is obligatory, just wondering what it's for?

also, maybe someone knows how to make theee atts invisible?


(cons 70 1) to be invisible

Edited by lastknownuser
  • Like 1
Posted

big thanx to you both 👍

Posted

You probably all ready know this, but for others following this. If you use:

 

(entget (car (entsel)))

 

in the command line it will return the entity DXF code description for that (there are LISPs that do the same). Copy this and remove the '-1', '5' and '330' entries - this is the basis for entmake or entmakex (entmakex if you want to use the entity as in (setq MyNewEnt (entmakex (list ..... )))   ).

 

If you entmake what you copy you will create a copy of the original entity. Anyway point being, if you are struggling with entmake, create a template entity as you want it, (entget.... ) it then you can modify the entmake code as required. Note that sometimes the order of the dxf codes is important too. I would ;; out parts so they can go back in again and check that it all still works OK.

 

Sometimes what you make needs an attsync, redraw or regen to show the entity properly - blocks tend to like an attsync

  • Like 2
Posted (edited)

Found this page today

https://documentation.help/AutoCAD-DXF

Great for finding DXF codes..

I also have a lisp that does list DXF codes from entities, but it lists only used ones, not all of them...

I reluctantly use attsync cause often I must move some attributes independently of block, and that command resets their position...

Also, wasn't aware that order is important, it's good to know, perhaps now I understand why some of my codes doesn't work

Edited by Tomislav

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