Jump to content

Need help iterating over whole drawing


K Baden

Recommended Posts

Good morning!

 

I am currently attempting to automate a few codes i have further. I currently have 3 separate codes that effectively creates an mleader style, updates old Qleader or plain leader/mtext/text entities to Mleaders, and update the style. I would like to know if there is a way to do this over the whole drawing at once. I've included credit to the pages in which i found these codes.

 

First, I create the MLeader Style

(Credit here:

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/create-multileader-style-with-lisp/m-p/7703795/highlight/false#M363951)

 

;;;
;;; Usage  : (CreateMLeaderStyle [NewStyleName] [ConfigList])
;;; Example: (CreateMLeaderStyle "Test"         '(("TextStyle" . "Standard")("TextHeight" . 2.5)))
;;;
;;; [NewStyleName] - String  -> Name of new MLeader Style
;;; [ConfigList]   - List    -> List with properties & values
;;;

(defun CreateMLeaderStyle (CMS_NewName CMS_Config / CMS_TextStyle CMS_MLeaderStyles CMS_NewMLeaderStyle CMS_Property CMS_ColorObject)   
  (if
     (or
        (and
           (setq CMS_TextStyle (cdr (assoc "TextStyle" CMS_Config)))
           (tblsearch "STYLE" CMS_TextStyle)
        )
        (not (cdr (assoc "TextStyle" CMS_Config)))
     )
     (progn
        (setq CMS_MLeaderStyles (vla-item (vla-get-Dictionaries (vla-get-ActiveDocument (vlax-get-acad-object))) "ACAD_MLEADERSTYLE"))
        (if
           (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list CMS_MLeaderStyles CMS_NewName)))
           (progn
              (setq CMS_NewMLeaderStyle (vla-AddObject CMS_MLeaderStyles CMS_NewName "AcDbMLeaderStyle"))
              (if
                 (not (cdr (assoc "TextStyle" CMS_Config)))
                 (vla-put-TextStyle CMS_NewMLeaderStyle (getvar "TEXTSTYLE"))
              )
              (foreach CMS_Item CMS_Config
                 (if
                    (and
                       (vl-consp CMS_Item)
                       (= (type (setq CMS_Property (car CMS_Item))) 'STR)
                       (not (listp (cdr CMS_Item)))
                       (vlax-property-available-p CMS_NewMLeaderStyle CMS_Property)
                    )
                    (cond
                       (
                          (wcmatch (strcase CMS_Property) "*COLOR*")
                          (setq CMS_ColorObject  (vlax-get-property CMS_NewMLeaderStyle CMS_Property))
                          (vla-put-ColorIndex CMS_ColorObject (cdr CMS_Item))
                          (vl-catch-all-apply 'vlax-put-property (list CMS_NewMLeaderStyle CMS_Property CMS_ColorObject))
                       )
                       (
                          T
                          (vl-catch-all-apply 'vlax-put-property (list CMS_NewMLeaderStyle CMS_Property (cdr CMS_Item)))
                       )
                    )
                 )
              )
              (princ (strcat "\n ** Created " CMS_NewName " MLeader style"))
           )
            (princ "\n ** Error: MLeader style already exists")
        )
     )
     (princ "\n ** Error: textstyle does not exist")
  )
  (princ)
)

(defun c:CreateCMLeader ()
  (CreateMLeaderStyle "CMLeader"
     (list 
        '("ArrowSize"               . 0.0625)
        '("DoglegLength"            . 0.0625)
        '("LandingGap"              . 0.03125)
        '("LeaderLineColor"         . 7)
        (cons "ScaleFactor"         (getvar "DIMSCALE"))
        '("TextColor"               . 7)
        '("TextHeight"              . 0.0625)
        '("TextLeftAttachmentType"  . 1)
        '("TextRightAttachmentType" . 1)
        '("TextStyle"               . "ROMANS")
     )
  )
  (princ)
)

 

Second, I change the old leaders (qleaders) to MLeaders

(Credit here:

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-quick-leader-to-multileader/td-p/2346536)

 

(defun C:LD2MLD (/ ent1 ent1-gcode ent1-type leader-pt-list leader-1st-pt leader-2nd-pt ent2 ent2-gcode ent2-type text-strg)

 (setq ent1(car(entsel "\nSelect a Leader: "))
       ent1-gcode(entget ent1)
       ent1-type(cdr(assoc 0 ent1-gcode))
 )
  (if(= ent1-type "LEADER")
    (progn
       (setq leader-pt-list(member(assoc 10 ent1-gcode) ent1-gcode)
             leader-1st-pt(cdr(car leader-pt-list))
             leader-2nd-pt(cdr(cadr leader-pt-list))
             ent2(car(entsel "\nSelect Text or Mtext: "))
             ent2-gcode(entget ent2)
             ent2-type(cdr(assoc 0 ent2-gcode))
       )
        (if(or(= ent2-type "TEXT")(= ent2-type "MTEXT"))
          (progn
             (setq text-strg(cdr(assoc 1 ent2-gcode)))
               (setvar "OSMODE" (boole 7 (getvar "OSMODE") 16384));osnap off
               (setvar "CMDECHO" 0);command echo off
                  (command "_.ERASE" ent1 ent2 "" "_.MLEADER" leader-1st-pt leader-2nd-pt text-strg)
               (setvar "CMDECHO" 1);command echo on
               (setvar "OSMODE" (boole 2 (getvar "OSMODE") 16384));osnap on
           )
        )
         (if(and(/= ent2-type "TEXT")(/= ent2-type "MTEXT"))(alert "Object selected is not a text or mtext"))
    )    
   )
         (if(/= ent1-type "LEADER")(alert "Object selected is not a leader"))

(c:UpdateLastMLeaderStyle)

(princ)
)

 

Last, I update the last selected MLeader to the new style.

(Credit here:

http://www.cadtutor.net/forum/showthread.php?75906-Set-MLeader-to-Existing-MLeader-Style-via-LISP)

 

(defun c:UpdateLastMLeaderStyle (/ ss styleName)
(vl-load-com)
 (if (and (setq ss (ssget "L" '((0 . "MULTILEADER"))))
          (dictsearch
            (namedobjdict)
            "ACAD_MLEADERSTYLE"
            (setq styleName "CMLeader")
          )
     )
   (progn
     (vlax-for x (setq ss
                        (vla-get-activeselectionset
                          (vla-get-activedocument (vlax-get-acad-object))
                        )
                 )
       (vla-put-stylename x styleName)
     )
     (vla-delete ss)
   )
   (cond (ss (prompt "\n** MLeader style name not found ** "))
         ((prompt "\n** No MLeaders selected ** "))
   )
 )
)

 

 

this works great. once I create the MLeader style, I can use the LD2MLD command to update, which also updates the style automatically with the last command.

 

My problem is, some drawings may have 100+ call outs that need updated.

Is there a way to automatically iterate over each leader and associated text, change to mleader, update the style, and then move on to the next without having to select each leader/text combo and re-entering the command for each call out?

 

As i said, this process does what i want, but it is almost just as tedious as just recreating the callout from scratch as an Mleader. Does anyone have any ideas for blanketing this routine over the entire drawing in one run?

Link to comment
Share on other sites

to get you started:

 

(defun C:CADTUTOR ( / allobjects n ensel enlist entype )
(setq allobjects (ssget "_X" (list (cons 0 "*TEXT,*LEADER"))))				;; Selection set of type of text and leaders.
(if allobjects									;; Check if there is a selection
	(progn									;; If there is...
		(setq n 0)							;; Set counter of objects
		(repeat (sslength allobjects)					;; Loop trough the objects
			(setq ensel (ssname allobjects n))
			(setq enlist (entget ensel))
			(setq entype (cdr (assoc 0 enlist)))
			(cond
				((wcmatch entype "*TEXT")
					<do stuff with text object>
				)
				((wcmatch entype "*LEADER")
					<do stuff with leader object>
				)
				(t
					(alert "Something went wrong!")
				)
			)
			(setq n (+ 1 n))
		)
	)
	(progn									;; If there is not...
		(alert "No text or leaders in drawing.")
	)
)
(princ)
)

Link to comment
Share on other sites

Thank you! I'm trying to get this working, though it seems to not be going well for me. It's giving me something like 15 lines that say "unknown command" and then asking me to select the text. Anyone have any pointers on what to do here? I understand why its asking for me to select text, but I'm not sure how to eliminate that line.. Any help is appreciated. Thanks in advance!

 

(defun C:CADTUTOR ( / allobjects n ensel enlist entype )
(setq allobjects (ssget "_X" (list (cons 0 "*TEXT,*LEADER"))))				;; Selection set of type of text and leaders.
(if allobjects									;; Check if there is a selection
	(progn									;; If there is...
		(setq n 0)							;; Set counter of objects
		(repeat (sslength allobjects)					;; Loop trough the objects
			(setq ensel (ssname allobjects n))
			(setq enlist (entget ensel))
			(setq entype (cdr (assoc 0 enlist)))
			(cond
				((wcmatch entype "*LEADER")
                                         (progn
                                           (setq leader-pt-list(member(assoc 10 ent1-gcode) ent1-gcode)
                                                 leader-1st-pt(cdr(car leader-pt-list))
                                                 leader-2nd-pt(cdr(cadr leader-pt-list))
                                                 ent2(car(entsel "\nSelect Text or Mtext: "))
                                                 ent2-gcode(entget ent2)
                                                 ent2-type(cdr(assoc 0 ent2-gcode))
                                           )
                                         )
				)

				((wcmatch entype "*TEXT")
				  (progn
                                           (setq text-strg(cdr(assoc 1 ent2-gcode)))
                                              (setvar "OSMODE" (boole 7 (getvar "OSMODE") 16384));osnap off
                                              (setvar "CMDECHO" 0);command echo off
                                                 (command "_.ERASE" ent1 ent2 "" "_.MLEADER" leader-1st-pt leader-2nd-pt text-strg)
                                              (setvar "CMDECHO" 1);command echo on
                                              (setvar "OSMODE" (boole 2 (getvar "OSMODE") 16384));osnap on
                                         )
				)
				(t
					(alert "Something went wrong!")
				)
			)
			(setq n (+ 1 n))
		)
	)
	(progn									;; If there is not...
		(alert "No text or leaders in drawing.")
	)
)
(princ)
)

 

 

 

 

EDIT:

 

I realized that the variables were all wrong after looking at this again and this is what i've gotten:

(defun C:CADTUTOR ( / allobjects n ensel enlist entype )
(setq allobjects (ssget "_X" (list (cons 0 "*TEXT,*LEADER"))))				;; Selection set of type of text and leaders.
(if allobjects									;; Check if there is a selection
	(progn									;; If there is...
		(setq n 0)							;; Set counter of objects
		(repeat (sslength allobjects)					;; Loop trough the objects
			(setq ensel (ssname allobjects n))
			(setq enlist (entget ensel))
			(setq entype (cdr (assoc 0 enlist)))
			(cond
				((wcmatch entype "*LEADER")
                                         (progn
                                           (setq leader-pt-list(member(assoc 10 ensel) ensel)
                                                 leader-1st-pt(cdr(car leader-pt-list))
                                                 leader-2nd-pt(cdr(cadr leader-pt-list))
                                           )
                                         )
				)

				((wcmatch entype "*TEXT")
				  (progn
                                           (setq text-strg(cdr(assoc 1 ensel)))
                                              (setvar "OSMODE" (boole 7 (getvar "OSMODE") 16384));osnap off
                                              (setvar "CMDECHO" 0);command echo off
                                                 (command "_.ERASE" ent1 ent2 "" "_.MLEADER" leader-1st-pt leader-2nd-pt text-strg)
                                              (setvar "CMDECHO" 1);command echo on
                                              (setvar "OSMODE" (boole 2 (getvar "OSMODE") 16384));osnap on
                                         )
				)
				(t
					(alert "Something went wrong!")
				)
			)
			(setq n (+ 1 n))
		)
	)
	(progn									;; If there is not...
		(alert "No text or leaders in drawing.")
	)
)
(princ)
)

 

I could be totally off, but from what i can tell, it seems like the ensel variable is the one that refers to the selected object depending on the conditional, so ive changed that in the code. I'm still not sure of how to name the text and leader within the ERASE command since they are conditional. should I erase within each wcmatch for text and leaders? basically, select the leader, get all the point info from it, then delete it? and same with the text?

 

My apologies if this is completely off. This is a bit more advanced than I am used to editing myself, hopefully it's not too bad!!

 

Thanks in advance for any advice!

Edited by K Baden
Link to comment
Share on other sites

I am still working on this. Here is what I have. It currently just gives me a bunch of alerts in a row for each instance of a leader on the drawing saying "object selected is not a leader".

 

This is the main code I wish to have operate over each leader/text combo:

 

(defun C:CADTUTOR ( / allobjects n ent1 ent1-gcode ent1-type leader-pt-list leader-1st-pt leader-2nd-pt layer text-strg )
(setq allobjects (ssget "_X" (list (cons 0 "*LEADER"))))				;; Selection set of type of text and leaders.
  (if allobjects									;; Check if there is a selection
(progn								    		;; If there is...
 (setq n 0)							 		;; Set counter of objects
  (repeat (sslength allobjects)							;; Loop trough the objects
     (setq ent1 (ssname allobjects n))
     (setq ent1-gcode (entget ent1))
     (setq ent1-type (cdr (assoc 0 ent1-gcode)))
	   (if(= ent1-type "*LEADER")
	     (progn
		       (setq leader-pt-list (member(assoc 10 ent1-gcode) ent1-gcode)
  		             leader-1st-pt (cdr(car leader-pt-list))
     		             leader-2nd-pt (cdr(cadr leader-pt-list))
		     layer (dxf 8 ent1-gcode)
         		     ent2 (car(SelectText ent1-gcode))
          	 	     ent2-gcode (entget ent2)
       		     ent2-type (cdr(assoc 0 ent2-gcode))
                       )
      			  (if(or(= ent2-type "TEXT")(= ent2-type "MTEXT"))
 		            (progn
   		              (setq text-strg(cdr(assoc 1 ent2-gcode)))
        		        (setvar "OSMODE" (boole 7 (getvar "OSMODE") 16384));osnap off
      			        (setvar "CMDECHO" 0);command echo off
			   (command "-layer" "s" layer "")
   		                   (command "_.ERASE" ent1 ent2 "" "_.MLEADER" leader-1st-pt leader-2nd-pt text-strg)
      			        (setvar "CMDECHO" 1);command echo on
      			        (setvar "OSMODE" (boole 2 (getvar "OSMODE") 16384));osnap on
                           )
                         )
      			  (if(and(/= ent2-type "TEXT")(/= ent2-type "MTEXT"))(alert "Object selected is not a text or mtext"))
	   )    

	   (if(/= ent1-type "*LEADER")(alert "Object selected is not a leader"))
  )
 (setq n (+ 1 n))
)
)
   (progn (alert "No text or leaders in drawing.")
  )
)
(princ)
)

 

Here is the SelectText function set that selects the associated text with each leader:

 

(defun KGA_Conv_Pickset_To_EnameList (ss / i ret)
 (if ss
   (repeat (setq i (sslength ss))
     (setq ret (cons (ssname ss (setq i (1- i))) ret))
   )
 )
)

; Return value: Non-empty pickset or nil.
; Erased enames are not added to the set.

(defun KGA_Conv_EnameList_To_Pickset (lst / ret)
 (setq ret (ssadd))
 (foreach enm lst (if (not (vlax-erased-p enm)) (ssadd enm ret)))
 (if (/= 0 (sslength ret)) ret)
)

; (GetAssocAnnotation (car (entsel)))
(defun GetAssocAnnotation (enm) ; Enm: ename of leader.
 (cdr (assoc 340 (entget enm)))
)

; (SelectText (KGA_Conv_Pickset_To_EnameList (ssget "_A" '((0 . "*TEXT")))))
; (sssetfirst nil (SelectText (ssget "_A" '((0 . "*TEXT")))))

(defun SelectText (ss / ret retAsListP) ; Ss can be a selection set or a list of enames.
 (if (listp ss)
   (setq retAsListP T)
   (setq ss (KGA_Conv_Pickset_To_EnameList ss))
 )
 (setq ret (vl-remove nil (mapcar 'GetAssocAnnotation ss)))
 (if retAsListP                           ; Type of return matches that of input.
   ret
   (KGA_Conv_EnameList_To_Pickset ret)
 )
)

 

 

Does anyone know what I'm missing here? This is more advanced than I'm used to doing myself. I just want it to select a leader, select the associated text, create the new mleader, then do the same over each leader/associated text in the drawing. I feel like I'm getting close, but it is definitely beyond my level of coding. Any advice helps!

Link to comment
Share on other sites

Quick thing I see is: (= ent1-type "*LEADER") should be (wcmatch ent1-type "*LEADER")

 

Also, the logic of this might be easier to read using COND.

Link to comment
Share on other sites

And then looking a bit closer,

(setq allobjects (ssget "_X" (list (cons 0 "*LEADER"))))

Will always get (m)leader objects so no need to check below.

Link to comment
Share on other sites

Tried using the COND, something ive not done before! I did notice that above in the original suggestion, but concluded it may not be necessary since I'm really only dealing with the leader (the text is selected after the leader selection based on association) which is why i got rid of it.. I could be totally wrong in thinking that. This code seemed to make logical sense to me, but didn't work so clearly there was something missing!

 

I added the COND back in below, which has led to a bad argument type: lentityp error. Any other ideas? I appreciate the advice! This code is teaching me a lot I didn't know.

 

(defun C:CADTUTOR ( / allobjects n ent1 ent1-gcode ent1-type leader-pt-list leader-1st-pt leader-2nd-pt layer text-strg )
(setq allobjects (ssget "_X" (list (cons 0 "*LEADER"))))				;; Selection set of type of text and leaders.
  (if allobjects									;; Check if there is a selection
(progn								    		;; If there is...
 (setq n 0)							 		;; Set counter of objects
  (repeat (sslength allobjects)							;; Loop trough the objects
     (setq ent1 (ssname allobjects n))
     (setq ent1-gcode (entget ent1))
     (setq ent1-type (cdr (assoc 0 ent1-gcode)))
	   (cond
	     (progn
		       (setq leader-pt-list (member(assoc 10 ent1-gcode) ent1-gcode)
  		             leader-1st-pt (cdr(car leader-pt-list))
     		             leader-2nd-pt (cdr(cadr leader-pt-list))
		     layer (dxf 8 ent1-gcode)
         		     ent2 (car(SelectText ent1-gcode))
          	 	     ent2-gcode (entget ent2)
       		     ent2-type (cdr(assoc 0 ent2-gcode))
                       )
      			  (if(or(= ent2-type "TEXT")(= ent2-type "MTEXT"))
 		            (progn
   		              (setq text-strg(cdr(assoc 1 ent2-gcode)))
        		        (setvar "OSMODE" (boole 7 (getvar "OSMODE") 16384));osnap off
      			        (setvar "CMDECHO" 0);command echo off
			   (command "-layer" "s" layer "")
   		                   (command "_.ERASE" ent1 ent2 "" "_.MLEADER" leader-1st-pt leader-2nd-pt text-strg)
      			        (setvar "CMDECHO" 1);command echo on
      			        (setvar "OSMODE" (boole 2 (getvar "OSMODE") 16384));osnap on
                           )
                         )
      			  (if(and(/= ent2-type "TEXT")(/= ent2-type "MTEXT"))(alert "Object selected is not a text or mtext"))
	     )    

	   (if(/= ent1-type "*LEADER")(alert "Object selected is not a leader"))
  )
 (setq n (+ 1 n))
)
)
   (progn (alert "No text or leaders in drawing.")
  )
)
(princ)
)

Link to comment
Share on other sites

  • 1 month later...

Good morning all!

 

I have come back to this yet again and have not been able to get it working as i wish it would.

Does anyone have any renewed ideas? I have the code working on a one by one basis, but it does not do the whole drawing at once.

 

Here is my current code. I get an error of "bad argument type: lentityp (-1 . )"

when attempting to use it. I want to be able to use the "CADTUTOR" command and have it update all the leaders and associated text on the drawing to Mleaders automatically.

I do have a TESTINGMLEADER command near the bottom, this is used to ensure the associated text function works properly by changing the layer, and it does. I am not entirely sure of how to utilize that function within the larger code above

Any ideas?

 

;;;
;;; Usage  : (CreateMLeaderStyle [NewStyleName] [ConfigList])
;;; Example: (CreateMLeaderStyle "Test"         '(("TextStyle" . "Standard")("TextHeight" . 2.5)))
;;;
;;; [NewStyleName] - String  -> Name of new MLeader Style
;;; [ConfigList]   - List    -> List with properties & values
;;;

(defun CreateMLeaderStyle (CMS_NewName CMS_Config / CMS_TextStyle CMS_MLeaderStyles CMS_NewMLeaderStyle CMS_Property CMS_ColorObject)   
  (if
     (or
        (and
           (setq CMS_TextStyle (cdr (assoc "TextStyle" CMS_Config)))
           (tblsearch "STYLE" CMS_TextStyle)
        )
        (not (cdr (assoc "TextStyle" CMS_Config)))
     )
     (progn
        (setq CMS_MLeaderStyles (vla-item (vla-get-Dictionaries (vla-get-ActiveDocument (vlax-get-acad-object))) "ACAD_MLEADERSTYLE"))
        (if
           (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list CMS_MLeaderStyles CMS_NewName)))
           (progn
              (setq CMS_NewMLeaderStyle (vla-AddObject CMS_MLeaderStyles CMS_NewName "AcDbMLeaderStyle"))
              (if
                 (not (cdr (assoc "TextStyle" CMS_Config)))
                 (vla-put-TextStyle CMS_NewMLeaderStyle (getvar "TEXTSTYLE"))
              )
              (foreach CMS_Item CMS_Config
                 (if
                    (and
                       (vl-consp CMS_Item)
                       (= (type (setq CMS_Property (car CMS_Item))) 'STR)
                       (not (listp (cdr CMS_Item)))
                       (vlax-property-available-p CMS_NewMLeaderStyle CMS_Property)
                    )
                    (cond
                       (
                          (wcmatch (strcase CMS_Property) "*COLOR*")
                          (setq CMS_ColorObject  (vlax-get-property CMS_NewMLeaderStyle CMS_Property))
                          (vla-put-ColorIndex CMS_ColorObject (cdr CMS_Item))
                          (vl-catch-all-apply 'vlax-put-property (list CMS_NewMLeaderStyle CMS_Property CMS_ColorObject))
                       )
                       (
                          T
                          (vl-catch-all-apply 'vlax-put-property (list CMS_NewMLeaderStyle CMS_Property (cdr CMS_Item)))
                       )
                    )
                 )
              )
              (princ (strcat "\n ** Created " CMS_NewName " MLeader style"))
           )
            (princ "\n ** MLeader style already exists")
        )
     )
     (princ "\n ** Error: textstyle does not exist")
  )
  (princ)
)

(defun c:CreateCMLeader ()
  (CreateMLeaderStyle "CMLeader"
     (list 
        '("ArrowSize"               . 0.0625)
        '("DoglegLength"            . 0.0625)
        '("LandingGap"              . 0.03125)
        '("LeaderLineColor"         . 7)
        (cons "ScaleFactor"         (getvar "DIMSCALE"))
        '("TextColor"               . 7)
        '("TextHeight"              . 0.0625)
        '("TextLeftAttachmentType"  . 1)
        '("TextRightAttachmentType" . 1)
        '("TextStyle"               . "ROMANS")
     )
  )
  (princ)
)



(defun C:CADTUTOR ( / ssLea n ent1 ent1-gcode ent1-type leader-pt-list leader-1st-pt leader-2nd-pt layer text-strg )


(c:CreateCMLeader)


(setq ssLea (ssget "_A" '((0 . "*Leader"))))         				;; Selection set of type of text and leaders.
  (if ssLea									;; Check if there is a selection
(progn								    		;; If there is...
 (setq n 0)							 		;; Set counter of objects
  (repeat (sslength ssLea)							;; Loop trough the objects
     (setq ent1 (ssname ssLea n))
     (setq ent1-gcode (entget ent1))
     (setq ent1-type (cdr (assoc 0 ent1-gcode)))
	   (cond
	     (progn
		       (setq leader-pt-list (member(assoc 10 ent1-gcode) ent1-gcode)
  		             leader-1st-pt (cdr(car leader-pt-list))
     		             leader-2nd-pt (cdr(cadr leader-pt-list))
		     layer (assoc 8 ent1-gcode)
         		     ent2 (car(SelectText ent1-gcode))
          	 	     ent2-gcode (entget ent2)
       		     ent2-type (cdr(assoc 0 ent2-gcode))
                       )
      			  (if(or(= ent2-type "TEXT")(= ent2-type "MTEXT"))
 		            (progn
   		              (setq text-strg(cdr(assoc 1 ent2-gcode)))
        		        (setvar "OSMODE" (boole 7 (getvar "OSMODE") 16384));osnap off
      			        (setvar "CMDECHO" 0);command echo off
			   (command "-layer" "s" layer "")
   		                   (command "_.ERASE" ent1 ent2 "" "_.MLEADER" leader-1st-pt leader-2nd-pt text-strg)
      			        (setvar "CMDECHO" 1);command echo on
      			        (setvar "OSMODE" (boole 2 (getvar "OSMODE") 16384));osnap on
                           )
                         )
      			  (if(and(/= ent2-type "TEXT")(/= ent2-type "MTEXT"))(alert "Object selected is not a text or mtext"))
	     )    

	   (if(/= ent1-type "*LEADER")(alert "Object selected is not a leader"))
  )
 (setq n (+ 1 n))
)
)
   (progn (alert "No text or leaders in drawing.")
  )
)
(princ)
(c:UpdateLastMLeaderStyle)
)




(defun C:TESTINGMLEADER ( / ssLea ssTxt)

 (if (setq ssLea (ssget "_A" '((0 . "*Leader"))))
   (progn
    (command "_.chprop" ssLea "" "_layer" "Fence" "")
     (if (setq ssTxt (SelectText ssLea))
       (command "_.chprop" ssTxt "" "_layer" "Fence" "")
     )
   )
 )

 (princ)
)


(defun KGA_Conv_Pickset_To_EnameList (ss / i ret)
 (if ss
   (repeat (setq i (sslength ss))
     (setq ret (cons (ssname ss (setq i (1- i))) ret))
   )
 )
)

; Return value: Non-empty pickset or nil.
; Erased enames are not added to the set.

(defun KGA_Conv_EnameList_To_Pickset (lst / ret)
 (setq ret (ssadd))
 (foreach enm lst (if (not (vlax-erased-p enm)) (ssadd enm ret)))
 (if (/= 0 (sslength ret)) ret)
)

; (GetAssocAnnotation (car (entsel)))
(defun GetAssocAnnotation (enm) ; Enm: ename of leader.
 (cdr (assoc 340 (entget enm)))
)

; (SelectText (KGA_Conv_Pickset_To_EnameList (ssget "_A" '((0 . "*TEXT")))))
; (sssetfirst nil (SelectText (ssget "_A" '((0 . "*TEXT")))))

(defun SelectText (ss / ret retAsListP) ; Ss can be a selection set or a list of enames.
 (if (listp ss)
   (setq retAsListP T)
   (setq ss (KGA_Conv_Pickset_To_EnameList ss))
 )
 (setq ret (vl-remove nil (mapcar 'GetAssocAnnotation ss)))
 (if retAsListP                           ; Type of return matches that of input.
   ret
   (KGA_Conv_EnameList_To_Pickset ret)
 )
)

Edited by K Baden
added code
Link to comment
Share on other sites

You are trying to entget a variable that is bound to an associated list (-1 . ) instead of trying to entget the ename contained in its cdr. I'm not sure where it is without sample drawing, and knowing what every function returns... I can explain the error you get though.

 

As an example, i have a text. Entsel enables me to pick it up and returns

( (200.708 32.4829 0.0))

if I use (car(entsel)) it returns the first part of the assoc list, the ename

If I entget it, using (setq elst (entget(car(entsel)))), it returns

((-1 . ) (0 . "MTEXT") (330 . ) (5 . "2A5") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbMText") (10 197.976 33.3221 0.0) (40 . 2.5) (41 . 53.1579) (46 . 0.0) (71 . 1) (72 . 5) (1 . "HELLO K BADEN")...)

As you can see, the -1 assoc is the entity ename, the same as my example above

If I use either (assoc -1 elst) or (car elst), it will return the following:

(-1 . )

I could now reproduce the error you get using (entget (car elst)) . It returns ;

error: bad argument type: lentityp (-1 . ).

I could fix it by using (entget (cdr (car elst))), and it would return exactly the same as my var elst.

 

An advice that I could give you is to put alerts or princ statements while debugging. By seeing which alert/princ statement is the last to have been evaluated, you can know which one made the evaluation stop and pinpoint the location of the error. For sure it is by trying to entget, it may be where you (entget ent2) as ent2 is bound to (car(SelectText ent1-gcode)). Again, I don't know what the SelectText function returns, so it is a shot in the dark.

 

Good luck, and happy hunting/coding :)

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