Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

entsel last

15 REPLIES 15
Reply
Message 1 of 16
andrew_k99
2762 Views, 15 Replies

entsel last

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
15 REPLIES 15
Message 2 of 16
sdanis
in reply to: andrew_k99

I'm not really clear on what you are trying to accomplish.
Could you provide more information?
Message 3 of 16
andrew_k99
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
Message 4 of 16
sdanis
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.
Message 5 of 16
Anonymous
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.
Message 6 of 16
sdanis
in reply to: andrew_k99

Dah!!! Brain cramp. Tail end of a long day 😉
Message 7 of 16
andrew_k99
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
Message 8 of 16
sdanis
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.
Message 9 of 16
Anonymous
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
Message 10 of 16
Anonymous
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
Message 11 of 16
Anonymous
in reply to: andrew_k99

i'm confused too.
entsel returns (enthandle . point), so (car (entsel)) should return an entity handle the same as (entlast).

--J
Message 12 of 16
andrew_k99
in reply to: andrew_k99

Thanks for the advise Constantin. I managed to re-write the code slightly to get what I need. I now have the following and it works.

FYI the C:test2 was just so I could test the partial routine, it is far from done.

(defun c:test2 ()
(if
(progn
(setq en (entlast))
(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)

)


A question of interest ... I noticed that you put the following in the brackets after defun C:test2 'ent / en enlist en2 enlist2 pnl_01_ht ins_pt new_ins'. If I am not mistaken doing this clears the values defined in the routine, is this good to do? Does it cause any problems if you don't do it?

Andrew
Message 13 of 16
Anonymous
in reply to: andrew_k99

"The values defined in the routine" are called variables. The variables can
be local and/or global. If you declare them as local, i.e. writing them on
the right side of the forward slash within the defun statement, they live
only for the time the routine is running and at the end, they are cleared.

In the other hand, the global variables, those who are not declared as
local, will "float" in the environment, keeping their last assigned value.
This can be good, but can be harmful also, because they can interfere with
some other global variables with the same name, left by some other LISP
routine. So if you need global variables for whatever reason, just make sure
they have unique and hard to duplicate names.

On the left side of that forward slash within the defun statement, you are
passing the arguments, i.e. kind of self declared variables that bring
values from outside the function into the function. This is handy when you
have a function that performs something but you don't know all the data from
the very beginning. Let's assume you need a function that prints all the
elements of a list, but you don't know that list yet.

(defun print_list_elements (the_list)
(if (= (type the_list) 'LIST)
(foreach element the_list
(print element)
)
(alert "Invalid argument type !")
)
(princ)
)

The above function will work with any valid list, no matter the length and
the type of the elements of that list. In order to use it, you have to call
it by passing the list as a variable or directly as a list:

(setq my_list (list 1 2 3))
(print_list_elements my_list)

or

(print_list_elements (list 1 2 3))

This allows for greater flexibility when writing the code.

Hope all this is clear enough,

Constantin



a écrit dans le message de news:
5415758@discussion.autodesk.com...
Thanks for the advise Constantin. I managed to re-write the code slightly
to get what I need. I now have the following and it works.

FYI the C:test2 was just so I could test the partial routine, it is far from
done.

(defun c:test2 ()
(if
(progn
(setq en (entlast))
(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)

)


A question of interest ... I noticed that you put the following in the
brackets after defun C:test2 'ent / en enlist en2 enlist2 pnl_01_ht ins_pt
new_ins'. If I am not mistaken doing this clears the values defined in the
routine, is this good to do? Does it cause any problems if you don't do it?

Andrew
Message 14 of 16
Tom Smith
in reply to: andrew_k99

>entsel returns (enthandle . point)

It returns entity name and point. The handle is a whole different thing.
Message 15 of 16
andrew_k99
in reply to: andrew_k99

Thanks a lot for the explanation Constantin. You've been a great help!!

Andrew
Message 16 of 16
Anonymous
in reply to: andrew_k99

You're welcome,

Constantin

a écrit dans le message de news:
5416908@discussion.autodesk.com...
Thanks a lot for the explanation Constantin. You've been a great help!!

Andrew

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost