Jump to content

Entmake help


Steven P

Recommended Posts

Good afternoon,

 

I have been trying to use entmake to create a block which works sort of using this as an example:

 

(entmake '((0 . "BLOCK") (2 . "MyNewBlock") (70 . 64) (10 4.0 5.0 0.0)))
(entmake '((0 . "LINE") (10 0 0) (11 2 2)))
(entmake '((0 . "ENDBLK")))
(entmake '((0 . "INSERT") (2 . "MyNewBlock") (10 6.0 6.0 0.0)))

(this creates a block with a single line, simple for my question).

 

First question, I would like to use variables as the line points, but I don't know how to do that, google hasn't helped much and I can't think of anything else to try, 

so

(entmake '((0 . "LINE")(10 0 0)(...

might become

(entmake '(0 . "LINE") (10 pt1 pt2)(....

 

Second question might be the same answer. I can rename the block after it is created (I think) - but it would be nicer to create it with the correct name to start with - what I am doing will create different blocks based on user input.

 

 

Thanks for any help or pointers, hope I have explained this clear enough

 

 

 

 

Link to comment
Share on other sites

Here's an existing example for non-attributed blocks:

;; Objects to Block  -  Lee Mac
;; Converts a selection of objects to a block reference.
 
(defun c:obj2blk ( / e i l n p s x )
    (if
        (and (setq s (ssget "_:L" '((-4 . "<NOT") (0 . "ATTDEF,VIEWPORT") (-4 . "NOT>"))))
            (progn
                (while
                    (not
                        (or (= "" (setq n (getstring t "\nSpecify Block Name <Anonymous>: ")))
                            (and
                                (snvalid n)
                                (null (tblsearch "BLOCK" n))
                            )
                        )
                    )
                    (princ "\nBlock name invalid or already exists.")
                )
                (if (= "" n)
                    (setq n "*U")
                )
                (setq p (getpoint "\nSpecify Base Point: "))
            )
        )
        (progn
            (entmake
                (list
                   '(0 . "BLOCK")
                    (cons 10 (trans p 1 0))
                    (cons 02 n)
                    (cons 70 (if (wcmatch n "`**") 1 0))
                )
            )
            (repeat (setq i (sslength s))
                (entmake (entget (setq e (ssname s (setq i (1- i))))))
                (if (= 1 (cdr (assoc 66 (entget e))))
                    (progn
                        (setq x (entnext e)
                              l (entget  x)
                        )
                        (while (/= "SEQEND" (cdr (assoc 0 l)))
                            (entmake l)
                            (setq x (entnext x)
                                  l (entget  x)
                            )
                        )
                        (entmake l)
                    )
                )
                (entdel e)
            )
            (if (setq n (entmake '((0 . "ENDBLK"))))
                (entmake
                    (list
                       '(0 . "INSERT")
                        (cons 02 n)
                        (cons 10 (trans p 1 0))
                    )
                )
            )
        )
    )
    (princ)
)

 

Link to comment
Share on other sites

Thanks,

Tharwat, that's about the only thing I didn't try yesterday! 

 

Lee, once again, that looks like the work of a genius, I'll try it out today.

Link to comment
Share on other sites

You're welcome @Steven P, I hope it helps - if necessary, the program could be stripped back to a function which simply accepts a selection set of objects, a basepoint, and a block name, and then generates the corresponding block definition (and block reference) using entmake. Hopefully the posted code demonstrates the techniques for accomplishing this, though of course, feel free to ask if you are unsure about anything.

Edited by Lee Mac
Link to comment
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
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...