Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
Andrew_K99
Posts: 200
Registered: ‎07-28-2006
Message 1 of 16 (346 Views)

entsel last

346 Views, 15 Replies
12-05-2006 01:05 PM
I have looked through the help pages and have found hundreds of answers that are close to what I need but not exactly.

I am in the process of writing a lisp routine that will insert in a block that contains 12 attributes. The routine prompts you to select two points and from that the routine calculates the values of the 12 attributes.

I need to be able to move around certain attributes depending on their values. I have the following bit of code that works great to search through a block for the attribute I want and then revises the insertion point. The dilemma is that you need to select the block, something I don't want the user to do. The block is the block that the routine is inserting.

The obvious solution (to me at least) was to use entlast. Unfortunately entsel and entlast return different values so I can't interchange them here.

Anyone have any idea how I can do this?
(other solutions besides this bit of code is fine as well)

(defun c:test ()
(if
(setq ent (entsel "\n Select a Block: "))
(progn
(setq en (car ent))
(setq enlist (entget en))
(if
(= (cdr (assoc 0 enlist)) "INSERT")
(progn
(if
(= (cdr (assoc 66 enlist)) 1)
(progn
(setq en2 (entnext en))
(setq enlist2 (entget en2))
(while
(/= (cdr (assoc 2 enlist2)) "LEVEL_01")
(princ "\n ")
(princ enlist2)
(setq en2 (entnext en2))
(setq enlist2 (entget en2))
)
)
)
)
)
)
)

(setq pnl_01_ht_change 5000)
(setq ins_pt (cdr (assoc 11 enlist2)))
(setq new_ins_pt (list (car ins_pt) (+ (cadr ins_pt) pnl_01_ht_change) (caddr ins_pt)))
(setq enlist2 (subst (cons 11 new_ins_pt) (assoc 11 enlist2) enlist2))
(entmod enlist2)
(entupd en2)

)

Thanks,
Andrew
Distinguished Contributor
sdanis
Posts: 203
Registered: ‎12-09-2003
Message 2 of 16 (346 Views)

Re: entsel last

12-05-2006 01:13 PM in reply to: Andrew_K99
I'm not really clear on what you are trying to accomplish.
Could you provide more information?
Distinguished Contributor
Andrew_K99
Posts: 200
Registered: ‎07-28-2006
Message 3 of 16 (346 Views)

Re: entsel last

12-05-2006 01:17 PM in reply to: Andrew_K99
I need the line in the code that reads (setq ent (entsel "\n Select a Block: ")) to select the block I am inserting with the routine.

Andrew
Distinguished Contributor
sdanis
Posts: 203
Registered: ‎12-09-2003
Message 4 of 16 (346 Views)

Re: entsel last

12-05-2006 01:25 PM in reply to: Andrew_K99
Does (setq LastInsertedBlock (cdr(assoc -1(entget (entlast))))) do what you need? It will return the entity name of the last block inserted. Then you can usen entget to see the assoc code for that block.
*Jeff Mishler
Message 5 of 16 (346 Views)

Re: entsel last

12-05-2006 01:34 PM in reply to: Andrew_K99
Uh, this: (cdr(assoc -1(entget (entlast))))

Is identical to this: (entlast)

with far less typing.......

Command: (entlast)


Command: (cdr(assoc -1(entget (entlast))))


wrote in message news:5415713@discussion.autodesk.com...
Does (setq LastInsertedBlock (cdr(assoc -1(entget (entlast))))) do what you
need? It will return the entity name of the last block inserted. Then you
can usen entget to see the assoc code for that block.
Distinguished Contributor
sdanis
Posts: 203
Registered: ‎12-09-2003
Message 6 of 16 (346 Views)

Re: entsel last

12-05-2006 01:38 PM in reply to: Andrew_K99
Dah!!! Brain cramp. Tail end of a long day ;-)
Distinguished Contributor
Andrew_K99
Posts: 200
Registered: ‎07-28-2006
Message 7 of 16 (346 Views)

Re: entsel last

12-05-2006 01:39 PM in reply to: Andrew_K99
yeah ... I just figured that one out Jeff. The problem is that (entlast) and (entsel) return different things.

I could dig through the entity using entlast and then use strcat to combine what I need but that seems like the a$$ backwards way of doing it.

Andrew
Distinguished Contributor
sdanis
Posts: 203
Registered: ‎12-09-2003
Message 8 of 16 (346 Views)

Re: entsel last

12-05-2006 01:42 PM in reply to: Andrew_K99
If I'm not mistaken entlast returns the entity name and entsel returns the entity name and the point selected.
*Constantin
Message 9 of 16 (346 Views)

Re: entsel last

12-05-2006 01:43 PM in reply to: Andrew_K99
Hi Andrew,

If you call (entlast) right after the insertion of the block and you have to
modify your code to read like this:

(setq ent (entlast))

instead of

(setq ent (entsel "\n Select a Block: "))

You fact, you should remove the c: because you say you don't need a command
with user interaction and pass the block entity name as argument, so your
code becomes (take care of the slash and how is placed):

(defun test (ent / en enlist en2 enlist2 pnl_01_ht ins_pt new_ins)
(if ent
(progn
(setq en (car ent))
(setq enlist (entget en))
(if (= (cdr (assoc 0 enlist)) "INSERT")
(progn
(if (= (cdr (assoc 66 enlist)) 1)
(progn
(setq en2 (entnext en))
(setq enlist2 (entget en2))
(while (/= (cdr (assoc 2 enlist2)) "LEVEL_01")
(princ "\n ")
(princ enlist2)
(setq en2 (entnext en2))
(setq enlist2 (entget en2))
)
)
)
)
)
)
)

(setq pnl_01_ht_change 5000)
(setq ins_pt (cdr (assoc 11 enlist2)))
(setq new_ins_pt
(list
(car ins_pt)
(+ (cadr ins_pt) pnl_01_ht_change)
(caddr ins_pt)
)
)
(setq enlist2
(subst
(cons 11 new_ins_pt)
(assoc 11 enlist2)
enlist2
)
)
(entmod enlist2)
(entupd en2)
(princ)
)


Then you call your function like this:

(test (entlast))

This will call the above function and pass the last inserted block (I repeat
that this works only if you call your function immediately after the
insertion
of the block is over, so make sure no other entity is created in between.)

HTH,

Constantin



a écrit dans le message de news:
5415699@discussion.autodesk.com...
I need the line in the code that reads (setq ent (entsel "\n Select a
Block: ")) to select the block I am inserting with the routine.

Andrew
*Jeff Mishler
Message 10 of 16 (346 Views)

Re: entsel last

12-05-2006 01:43 PM in reply to: Andrew_K99
What do you mean by they " return different things"? When I insert an
attributed block, (entlast) returns the of that blockreference.

wrote in message news:5415749@discussion.autodesk.com...
yeah ... I just figured that one out Jeff. The problem is that (entlast)
and (entsel) return different things.

I could dig through the entity using entlast and then use strcat to combine
what I need but that seems like the a$$ backwards way of doing it.

Andrew
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.