Jump to content

(entlast) function?


tzframpton

Recommended Posts

I know (entlast) means the last entity (or object) that was made or used or whatever... but is there a funtion that calls the last two entities? or three, or whatever you want it to be?

Link to comment
Share on other sites

isn't it entsel ? (just a guess perhaps, but that may give you the chance to select entities, i'm a nooby with that kind of programming) AND have also just returned from holidaying in the sun for the past 12 days

Link to comment
Share on other sites

Guest Alan Cullen

Styk.....

 

Use entlast, or use the ability to create a selection set of the last entity created, then bring them back in when needed.....

 

I rarely use entlast...I prefer to have greater control over my code....even though it means an extra couple of lines of code....

 

I'm at home at the moment.....so tomorrow I'll have a bit of a hunt to give you some examples.....

 

P.S. you seem to be doing pretty damn good with your learning....:lol: :lol: :D :D

Link to comment
Share on other sites

P.S. you seem to be doing pretty damn good with your learning....

 

haha, yeah.... i told you man, i'm into this Lisp thing. the only real trouble i'm having is thinking "okay, what's the best way of starting this program" and "okay, where do i go next" while i'm in the code. give me a year and we'll see where i'm at... :wink:

 

Back to topic... what i'm specifically trying to do is set my QLEADER to default on a certain layer every time. but there's two parts to a leader, the MTEXT and the LEADER itself, making it two seperate entities. I tried to set the CLAYER variable 1st for the leader, then use the ENTLAST funtion for the mtext, but the program goes nuts because there's apparently the QLEADER isn't as simple as I had planned. Anyways... that's about it. :)

Link to comment
Share on other sites

how about setting CLAYER at the start of your lisp to set the layer for both the leaders and the mtext portions of the QLEADER. then at the end of the lisp (after you have finished drawing your qleaders), you run some form of entsel to capture all the leaders and force them onto a separate layer.

i mean, is that even possible ?

i presume it will be

Link to comment
Share on other sites

Guest Alan Cullen

Having never used leaders before in a routine.....I can see a lot of problems.......you have to issue the command in lisp....then go back to the edit area (graphics) to set your location for the leader...then return to lisp to keep going.....

 

Have fun, mate :lol: :lol: :lol:

 

Just read back on your post.......yeah, set the layer first...get away from using ENTLAST....it causes more problems then it's worth.....people like asmi and kplg can do it...because they are absolute gurus at it.....but mere mortals like us....we will struggle....o:)

Link to comment
Share on other sites

Alan is right. At most cases algorithm Change Environment > Draw > Restore Environment more convinient. But not in all cases.

 

Several entities at once are called the Selection Set. It can be created by SSGET or SSADD functions. In your case algorithm aproximetely that:

 

[color="Blue"]; store last entity before draw[/color]
(setq lastEnt(entlast))

[color="Red"]; ***** draw something *****[/color]

[color="Blue"]; create empty selection set[/color]
(setq selSet(ssadd))

[color="#0000ff"]; while exists next entity add it to selection set[/color]
(while(setq lastEnt(entnext lastEnt))
 (ssadd lastEnt selSet)
 ); end while

 

Now you have Selection Set with a several entities. You can extract each entity in loop and do some actions with it:

 

[color="#0000ff"]; set counter to 0[/color]
(setq Counter 0)

[color="#0000ff"]; repeat how many entities in selection set[/color]
(repeat(sslength selSet))

[color="#0000ff"]; extract entity by it number[/color]
(setq curEnt(ssname selSet Counter))

[color="Red"]; ***** do something with Curent Entity *****[/color]

[color="Blue"]; add 1 to counter[/color]
(setq curEnt(1+ curEnt))

); end repeat 

 

There are also other more elegant ways to get the same result. However if we speak such algorithms about bases it is necessary to know. It is necessary to tell that LISP-programmers do not like Selection Sets and prefer to them lists because LISP it is language of processing of lists and it gives for this purpose unique opportunities.

Link to comment
Share on other sites

Guest Alan Cullen

I think what asmi is saying is......get used to using lisp to create selection sets...it really is so easy when you get the hang of it....

 

I have to agree with asmi.......so many people shy off using this ability...like they shy off going into the data base to change something....yet the ability to do that is so inherent....it is the very basis of lisp......:)

Link to comment
Share on other sites

to create leader by lisp you have to decide what kind of annotation object you will use. Usually i'm using this algorythm:

- get start point of leader

- get end point of leader

- create an annotation object (by activex) with setting layer, lineweight, linetype, color etc

- create a leader object (by activex) with setting layer, lineweight, linetype, color etc

- getting a pointer to leader object.

All other ways hasn't good result :(

For example, code

(defun try (/ ent lst)
 (setq ent (entlast))
 (command "_.leader")
 (while (/= (logand (getvar "cmdactive") 31) 0)
   (command pause) ; the error!!!
   ) ;_ end of while
 (while (setq ent (entnext ent))
   (setq lst (cons ent lst))
   ) ;_ end of while
 (foreach item lst
   (entmod (subst (cons 8 "qwert")
                  (assoc 8 (entget item))
                  (entget item)
                  ) ;_ end of subst
           ) ;_ end of entmod
   (entupd item)
   ) ;_ end of foreach
 ) ;_ end of defun

whill crashes AutoCAD within creating annotation :(

Link to comment
Share on other sites

Put leaders to certain layer... I it seems to me saw earlier :shock:

http://www.cadtutor.net/forum/showthread.php?t=13528&highlight=qleader

 

 

Edit:

 

Hmm... I don't see new messages in that thread... It seems has realy problems in 2002. I shall try to understand them... However you can try this code.

 

>kpblc

 

Yes, now I have recollected that with drawing LEADER I too had problems.

 

Sleep, now only sleep...

Link to comment
Share on other sites

Function (entlast) always returns last (not erased) entity, it is necessary to store it right after draw. Here the example of function which will return the list of entities from selected entity up to the last entity.

 

(defun Ent_List_to_End(ent / a)
 (reverse
   (if(setq a(entnext ent))
      (cons ent(Ent_List_to_End a))
     ); end reverse
   ); end if
 ); Ent_List_to_End

Link to comment
Share on other sites

  • 1 year later...

hey guys how do you process one selection set and create more from it.

 

like say i wanted to split one selection set into like 4 different sets to do somethg with.. off hand say

 

(setq ss1 (ssget));INITIAL SET

;if i wanted to create a selection set from the INITIAL SET like 

(setq ss2 (ssget "P" '((0 . "text,mtext"))))

;then another from the INITIAL SET to collect all objects that are bylayer

(setq ss3 (ssget "P" '((62 . 256))))

;then if i wantd to make another selction set from the INITIAL SELECTION SET say i wanted to get everything from the initial selection set apart from text and mtext

(setq ss4 (ssget "P" '((-4 . "<NOT")(0 . "text,mtext")(-4 . "NOT>))))

 

ok i know using the

(ssget "P")

isn't working - because i want to create my new selection sets from the initial selection set ss1 - so my question is as asked above - how do you split an initial selction set into either individual selection sets or transfer them into lists???

 

what methods does everyone use??

 

Please guide me in the correct path.

 

Thank you

Link to comment
Share on other sites

Russell,

In your command line test cases with (ssget "P") each time the "P"revious selection set gets smaller and smaller. It's not the original selection set SS1. SS2 was created from SS1. SS3 from SS2 and SS4 from SS3. If you are intending to make selection sets SS2, SS3 and SS4 from SS1, here is a method that might work for you.

 

Terry Cadd

(defun c:SS1234 (/ Cnt# EntColor@ EntList@ EntName^ EntType$)
 (if (setq SS1 (ssget))
   (progn
     (setq SS2 (ssadd));Text or Mtext
     (setq SS3 (ssadd));Bylayer
     (setq SS4 (ssadd));Not Text or Mtext
     (setq Cnt# 0)
     (repeat (sslength SS1)
       (setq EntName^ (ssname SS1 Cnt#))
       (setq EntList@ (entget EntName^))
       (setq EntType$ (cdr (assoc 0 EntList@)))
       (setq EntColor@ (assoc 62 EntList@))
       (if (member EntType$ (list "TEXT" "MTEXT"))
         (ssadd EntName^ SS2)
       );if
       (if (not EntColor@)
         (ssadd EntName^ SS3)
       );if
       (if (not (member EntType$ (list "TEXT" "MTEXT")))
         (ssadd EntName^ SS4)
       );if
       (setq Cnt# (1+ Cnt#))
     );repeat
     (princ "\nSelection sets created: SS1 ")
     (if (> (sslength SS2) 0) (princ "SS2 "))
     (if (> (sslength SS3) 0) (princ "SS3 "))
     (if (> (sslength SS4) 0) (princ "SS4"))
   );progn
 );if
 (princ)
);defun

This should have probably be broken out into a separate thread. But anyway...

Link to comment
Share on other sites

thank you Terry.

I have been trying with no avail and i know it can be done.

I have looked through the help file and honestly just needed someone to show me.

 

Thanks for that - i'm heading out on site now but tonight i'll have a look at it a edit the code i've been working on and repost for any comments.

 

Thanks

Link to comment
Share on other sites

Russell,

Here's a function that I've found to be very useful for displaying the dxf information of entities on the text screen in an easy to read format. Most programmers have a version of it, or one that they've created on their own.

The reason that I've included this function is that it might be useful for you while creating selection sets. If you create two lines on the same layer and change the color of one of them and run the LED function on both of the lines, you will notice that the line that you changed the color now has an assoc 62 dxf list. i.e. (62 . 1) red. Your command line test: (setq ss3 (ssget "P" '((62 . 256)))) would return nil, because the range of a color change is from 1 to 255. If the color is ByBlock you will see an assoc (62 . 0).

I hope this function helps you out, if you don't already have it.

Terry

 

(defun c:LED (/ Cnt# DxfList@ EntList@ SS&)
 (princ "\nList Entity Data")
 (if (setq SS& (ssget))
   (progn
     (textscr)
     (princ "\n------------------------------")
     (setq Cnt# 0)
     (repeat (sslength SS&)
       (setq EntList@ (entget (ssname SS& Cnt#)))
       (foreach DxfList@ EntList@
         (princ "\n")(princ DxfList@)
       );foreach
       (princ "\n------------------------------")
       (setq Cnt# (1+ Cnt#))
     );repeat
   );progn
 );if
 (princ)
);defun c:LED

We may be getting off the subject of (entlast), and it may be time to start a new thread.

Link to comment
Share on other sites

ohhh thank you heaps.

 

You have no idea how puzzled i have been when i ask people about selection sets and they come up with something so quick.

 

This code helps a lot.

 

Thank you kindly for sharing.

 

Russell

Link to comment
Share on other sites

Also how would i make a selection set of all text and mtext that is currently underlined using this ssadd method??

 

I'm trying to incorporate with a filter of something like

 

'(
(-4 . "<OR")
(-4 . "<AND") 
 (0 . "TEXT");select text objects
 (1 . "%%U*");that are underlined
(-4 . "AND>")
(-4 . "<AND")
 (0 . "MTEXT");select mtext objects 
 (1 . "#L*");that are underlined
(-4 . "AND>")
(-4 . "OR>")
   )

 

It works for the text that is underlined but not the mtext

Link to comment
Share on other sites

Ok i know its very long winded and could be shortened but hey it works and i'll clean it up later.

 

Pretty much i need to update a lot of details to standard layers corresponding to the current color of the object and entity type hatch/text/mtext etc

 

So anyways have a look - i said i would post what i was working on..

Noone will probally use it and if they do you guys would probally write it in like 20 lines but have a look and if you can show me how to reduce the ammount of code written throughout sections that would help heaps!!

 

Cheers have a good weekend

Russ

 

credit to

;TOLAY FUNCTION by Michael Puckett.

;QWRTZ for the BYCOL function

;n terry cad for the selection sets

 

(defun Table (s / d r)
(while (setq d (tblnext s (null d)))
(setq r (append r (list (cdr (assoc 2 d)))))
)
)
;################################
;Convert to bycolor Function
;################################
(defun BYCOL ()
 (if SS2
   (progn
     (setq I -1)
     (repeat (sslength SS2)
(setq I (+ I 1))
(setq EN (ssname SS2 I))
(setq EL (entget EN))
(setq LAY (cdr (assoc 8 EL)))
(setq LL (tblsearch "layer" LAY))
(setq LCP (list (assoc 62 LL)))
(setq CP (list (assoc 62 EL)))
(setq EL (append EL LCP))
(setq EL (subst LCP CP EL))
(entmod EL)
(entupd EN)
     );end repeat
   );end progn
   (princ "\n 0 selected")  ; = If-Else procedure
 );end if                       
 (setq ss2 nil)
 (PRINC)
);End BYCOL
;#######################################################################
; Put objects into layers pending color Function
;#######################################################################
(defun TOLAY (/ dwg_layers elist en layer layer_data layer_list state )
(setq dwg_layers (table "layer"))
(princ "\n..CREATING STANDARD LAYERS")
(setq layer_list (list

    '("LINE10" "Continuous" 0 9);<--layer name, linetype, lineweigth, color index
    '("LINE18" "Continuous" 0 
    '("LINE30" "Continuous" 0 7)
    '("LINE35" "Continuous" 0 3)
    '("LINE40" "Continuous" 0 2)
    '("LINE50" "Continuous" 0 4)
    '("LINE60" "Continuous" 0 1)
    '("LINE70" "Continuous" 0 5)
    '("LINE100" "Continuous" 0 6)
    '("LINE251" "Continuous" 0 251)
    '("LINE252" "Continuous" 0 252)
    '("Txt" "Continuous" 0 7)
    '("HATCH" "Continuous" 0 
    '("DIM" "Continuous" 0 7)))

(foreach itm layer_list
 (if (not (member (car itm) dwg_layers))
(entmake
(list
(cons 0 "LAYER")
(cons 100  "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 2 (car itm));name 
(cons 62 (last itm));color
(cons 6 (cadr itm)) ;line type
(cons 70 0);state
(cons 290 1);plot
(cons 370 (caddr itm));lineweight
);end list
);end entmake
   );end if
 );end foreach
(while (setq en (ssname ss1 0))
      (setq elist (entget en))
      (setq layer (cdr (assoc 8 elist)))
 (if (= 1 (logand 1
(setq state
(cdr (assoc 70
(setq layer_data (entget (tblobjname "layer" layer))))))))
       (entmod (subst (cons 70 0)(assoc 70 layer_data) layer_data)))

  (cond ((and (= 9 (cdr (assoc 62 elist)))
       (not (wcmatch (cdr (assoc  0 elist)) "LEADER,MTEXT,TEXT,HATCH,DIMENSION")))
       (entmod (subst (cons 8 "LINE10")(assoc 8 elist) elist)))
       ((and (= 8 (cdr (assoc 62 elist)))
       (not (wcmatch (cdr (assoc  0 elist)) "LEADER,MTEXT,TEXT,HATCH,DIMENSION")))
       (entmod (subst (cons 8 "LINE18")(assoc 8 elist) elist)))
       ((and (= 7 (cdr (assoc 62 elist)))
       (not (wcmatch (cdr (assoc  0 elist)) "LEADER,MTEXT,TEXT,HATCH,DIMENSION")))
       (entmod (subst (cons 8 "LINE30")(assoc 8 elist) elist)))
       ((and (= 3 (cdr (assoc 62 elist)))
       (not (wcmatch (cdr (assoc  0 elist)) "LEADER,MTEXT,TEXT,HATCH,DIMENSION")))
       (entmod (subst (cons 8 "LINE35")(assoc 8 elist) elist)))
       ((and (= 2 (cdr (assoc 62 elist)))
       (not (wcmatch (cdr (assoc  0 elist)) "LEADER,MTEXT,TEXT,HATCH,DIMENSION")))
       (entmod (subst (cons 8 "LINE40")(assoc 8 elist) elist)))
       ((and (= 4 (cdr (assoc 62 elist)))
       (not (wcmatch (cdr (assoc  0 elist)) "LEADER,MTEXT,TEXT,HATCH,DIMENSION")))
       (entmod (subst (cons 8 "LINE50")(assoc 8 elist) elist)))
       ((and (= 1 (cdr (assoc 62 elist)))
       (not (wcmatch (cdr (assoc  0 elist)) "LEADER,MTEXT,TEXT,HATCH,DIMENSION")))
       (entmod (subst (cons 8 "LINE60")(assoc 8 elist) elist)))
       ((and (= 5 (cdr (assoc 62 elist)))
       (not (wcmatch (cdr (assoc  0 elist)) "LEADER,MTEXT,TEXT,HATCH,DIMENSION")))
       (entmod (subst (cons 8 "LINE70")(assoc 8 elist) elist)))
       ((and (= 6 (cdr (assoc 62 elist)))
       (not (wcmatch (cdr (assoc  0 elist)) "LEADER,MTEXT,TEXT,HATCH,DIMENSION")))
       (entmod (subst (cons 8 "LINE100")(assoc 8 elist) elist)))
       ((and (= 251 (cdr (assoc 62 elist)))
       (not (wcmatch (cdr (assoc  0 elist)) "LEADER,MTEXT,TEXT,HATCH,DIMENSION")))
       (entmod (subst (cons 8 "LINE251")(assoc 8 elist) elist)))
       ((and (= 252 (cdr (assoc 62 elist)))
       (not (wcmatch (cdr (assoc  0 elist)) "LEADER,MTEXT,TEXT,HATCH,DIMENSION")))
       (entmod (subst (cons 8 "LINE252")(assoc 8 elist) elist)))


((= "TEXT" (cdr (assoc  0 elist)))
       (entmod (subst (cons 8 "Txt")(assoc 8 elist) elist)))
((= "MTEXT" (cdr (assoc  0 elist)))
       (entmod (subst (cons 8 "Txt")(assoc 8 elist) elist)))
((= "LEADER" (cdr (assoc  0 elist)))
       (entmod (subst (cons 8 "Txt")(assoc 8 elist) elist)))
((= "HATCH" (cdr (assoc  0 elist)))
       (entmod (subst (cons 8 "hatch")(assoc 8 elist) elist)))
 ((= "DIMENSION" (cdr (assoc 0 elist)))
       (entmod (subst (cons 8 "Dim")(assoc 8 elist) elist)))
(t nil)
)
     (entupd en)
 (ssdel en ss1)
 );end while
(setq ss1 nil)
  (princ)
);End TOLAY   
;#######################################################################
; MAKE COLOR TO BYLAYER FUNCTION
;#######################################################################
(DEFUN BYLAY ()
 (if SS3
   (progn
     (setq I -1)
     (repeat (sslength SS3)
(setq I (+ I 1))
(setq EN (ssname SS3 I))
(setq EL (entget EN))
(setq EL
       (subst (cons 62 256)
       (assoc 62 EL)
       EL
       )
)
(entmod EL)
     )
   )
 )
 (setq ss3 nil)
 (PRINC)
);end BYLAY
;#######################################################################
; MAKE TEXT COLOR TO YELLOW
;#######################################################################
(DEFUN TCOL ()
 (if SS4
   (progn
     (setq I -1)
     (repeat (sslength SS4)
(setq I (+ I 1))
(setq EN (ssname SS4 I))
(setq EL (entget EN))
(setq EL
       (subst (cons 62 2)
       (assoc 62 EL)
       EL
       )
)
(entmod EL)
     )
   )
 )
 (setq ss4 nil)
 (PRINC)
);end TCOL
;#######################################################################
; MAKE UNDERLINED TEXT COLOR TO RED
;#######################################################################
(DEFUN TRED ()
 (if SS5
   (progn
     (setq I -1)
     (repeat (sslength SS5)
(setq I (+ I 1))
(setq EN (ssname SS5 I))
(setq EL (entget EN))
(setq EL
       (subst (cons 62 1)
       (assoc 62 EL)
       EL
       )
)
(entmod EL)
     )
   )
 )
 (setq ss5 nil)
 (PRINC)
);end TRED
;#######################################################################
; MAIN FUNCTION
;#######################################################################
(defun C:STANDARD (/ I EntC EntL EntN EntT)
(setvar "cmdecho" 0) 

(princ "\n ...SELECT OBJECTS TO CONVERT TO STANDARD...")
(if (setq ss1 (ssget));selection set 1 (ss1) is used for the TOLAY function
(progn

;#####################################
;CREATE SS5 FOR TRED FUNCTION
;#####################################
(setq ss5 (ssget "P"
'(
(-4 . "<OR")
(-4 . "<AND") 
 (0 . "TEXT");select text objects
 (1 . "*%%U*");that are underlined
(-4 . "AND>")
(-4 . "<AND")
 (0 . "MTEXT");select mtext objects 
 (1 . "{*\L*}");that are underlined
(-4 . "AND>")
(-4 . "OR>")
   )
)
)
;####################################
(setq ss2 (ssadd));entities that are Currently COLOR BYLAYER to be converted to BYCOLOR by BYCOL function
(setq ss3 (ssadd));entities that are not text or mtext
(setq ss4 (ssadd));All text or mtext entities
(setq I -1)
(repeat (sslength ss1)
(setq I (+ I 1))
(setq EntN (ssname ss1 I))
(setq EntL (entget EntN))
(setq EntT (cdr (assoc 0 EntL)))
(setq EntC (assoc 62 EntL))
;BYCOL
;if entities selected in ss1 are currently color bylayer add to ss2 
(if (not EntC)
(ssadd EntN ss2)
);if
;BYLAY
;if entities selected in ss1 are not text or mtext add to ss3
(if (not (member EntT (LIST "TEXT" "MTEXT")))
(ssadd EntN ss3)
)
;if entities selected in ss1 are text or mtext add to ss4
(if (member EntT (list "TEXT" "MTEXT"))
(ssadd EntN ss4)
);if

);repeat

);progn
);if
(BYCOL);uses SS2
(princ "\n..CONVERTED EACH ENTITIES COLOR TO BYCOLOR")
(TOLAY);uses ss1
(princ "\n..CONVERTED OBJECTS TO SET STANDARD LAYERS")
(BYLAY);uses ss3
(princ "\n..CONVERTED OBJECTS COLOR TO BYLAYER")
(TCOL);uses ss4
(princ "\n..CONVERTED TEXT AND MTEXT OBJECTS COLOR TO YELLOW")
(TRED)
(princ "\n..CONVERTED UNDERLINED TEXT AND MTEXT OBJECTS COLOR TO RED")
(command "_.-purge" "_LT" "" "_N")
(command "_.-purge" "_LA" "" "_N")
(setvar "cmdecho" 1)
(PRINC)
);END STANDARD
;################################################



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