Jump to content

Layername's to Mleader ; error lentityp


Recommended Posts

Posted

hey all

 

I'm try to put the name of selected layers to a Mleader.

Keep getting; error bad argument type: lentitype ("layer1" "layer2" "layer3")

i think this is a correct string list, can i get it in a mleader with each string on the next line?

 

(defun c:LTL (/ spc p1 p2 str lead)
 (vl-load-com)
 ;; Tharwat 08. 07. 2011
 (cond ((not acdoc)
        (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
       )
 )
 (setq spc (if (> (vla-get-activespace acdoc) 0)
             (vla-get-modelspace acdoc)
             (vla-get-paperspace acdoc)
           )
 )
 (while
   (and
     (setq p1 (getpoint "\n specify First Point :"))
     (setq p2 (getpoint p1 "\n Specify Second point :"))

;;;

(setq ss (ssget))
 (progn
   (repeat (setq i (sslength ss))
     (setq layer (cdr (assoc 8 (entget (ssname ss (setq i (1- i)))))))
     (if (not (member layer lst)) (setq lst (cons layer lst)))
   )
   (setq lst (acad_strlsort lst))
 )

;;;

(setq str lst)

;;;
     
   )
    (progn
      (setq lead (vla-addmleader
                   spc
                   (vlax-make-variant
                     (vlax-safearray-fill
                       (safearray vlax-vbdouble '(0 . 5))
                       (apply 'append (list p1 p2))
                     )
                   )
                   0
                 )
      )
      (vla-put-textstring lead (cdr (assoc 8 (entget str))))
    )
 )
 (princ)
)

thx for the help

 

ps not native english

Posted (edited)

(vla-put-textstring
        lead
       [color=navy] (apply 'strcat (mapcar '(lambda (x) (strcat x "\\P")) str))[/color]
        )

Remember to localized the lst variable or reset at every loop

 

(defun c:LTL (spc p1 p2 str lead [i][b] lst[/b][/i])

...
(setq [color=blue][i][b]lst nil[/b][/i][/color] p1 (getpoint "\n specify First Point :"))....

Edited by pBe
wrong assumption :D
Posted (edited)

pBe thx voor de help

now it works perfect

 

i am looking at the code

i don't understand this line

 

... (setq [color=blue][i][b]lst nil[/b][/i][/color] p1 (getpoint "\n specify First Point :"))....

setq and then 3 variable ?

sorry just start learning and i'm not that good at it

 

 

maybe some help on how to count the objects in my selection on each layer ;)

 

Greetz john

Edited by johmmeke
Posted
pBe thx voor de help

now it works perfect

 

Good for you :)

 

i am looking at the code

i don't understand this line

 

... (setq [color=blue][i][b]lst nil[/b][/i][/color] p1 (getpoint "\n specify First Point :"))....

setq and then 3 variable ?

sorry just start learning and i'm not that good at it

 

same as

(setq lst nil)
(setq p1 (getpoint "\n specify First Point :"))

 

But with the and condition we cannot code it that way, as it evaluates to nil at the first expression and will exit the loop.

 

There's nothing magical about that john, the way the original code was written (kudos to Tharwat) at every loop it checks the lst variable for the selected entities layer name.

 

To explain to you the effect without resetting the lst variable

Lets say selected entities layer are "B1" and "C4"

(if

(not (member layer lst))

(setq lst (cons layer lst)))

 

same goes for C4 layer name.

 

("B1" "C4") as current value for lst variable

 

Now for next loop, selected objects layers are "D5" and "E1"

 

Layers "D5" and "E1" will be included on the lst.

 

Current value of lst variable would be ("B1" "C4" "D5" "E1") but remember you did not select any objects on "B1" or "C4" layer. and you will get "B1" "C4" "D5" "E1" as string value for you mleader. hence the reset at the start of the loop.

 

But then again, we can always reset the lst variable here to avoid confusion on your part.

(setq str lst [b][i][color="blue"]lst nil[/color][/i][/b])

 

as for this one

maybe some help on how to count the objects in my selection on each layer

 

Yes, it can be done :D Go ahead and show us the desired result.

Posted

pBE thx for the time you put in to explain this to me.

 

For the desired result..

i post a screen shot of it. To keep it simple i have given the layers the name of the colors the lines have, the elipse is my selection.

 

leader.jpg

 

so it only counts the lines i select ..

 

please keep the code simple ;)

 

greetz John

Posted

(defun c:LTL (/ spc p1 p2 str lead f lst)
 (vl-load-com)
 ;; Tharwat 08. 07. 2011		;;
 ;; modified by pBe sep 15 2012	;;
 
 (cond ((not acdoc)
        (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
       )
 )
 (setq spc (if (> (vla-get-activespace acdoc) 0)
             (vla-get-modelspace acdoc)
             (vla-get-paperspace acdoc)
           )
 )
 (while
   (and
     (setq p1 (getpoint "\n specify First Point :"))
     (setq p2 (getpoint p1 "\n Specify Second point :"))
(setq ss (ssget))
 (progn
   (repeat (setq i (sslength ss))
     (setq layer (cdr (assoc 8 (entget (ssname ss (setq i (1- i)))))))
    [color="blue"] (if (setq f (assoc layer lst))
        (setq lst (subst (list layer (1+ (cadr f))) f lst))
	(setq lst (cons (list layer 1) lst)))
   )[/color]
  [color="blue"] (setq lst (vl-sort lst '(lambda (a b)
	     (< (car a)(car b)))))[/color]
 )
   )
    (progn
      [color="blue"](setq str (mapcar '(lambda (j)
   (strcat (itoa (cadr j)) "x " (car j))) lst))[/color]
      (setq [color="blue"]lst nil[/color] lead (vla-addmleader
                   spc
                   (vlax-make-variant
                     (vlax-safearray-fill
                       (safearray vlax-vbdouble '(0 . 5))
                       (apply 'append (list p1 p2))
                     )
                   )
                   0
                 )
      )
      (vla-put-textstring
        lead
        (apply 'strcat (mapcar '(lambda (x) (strcat x "\\P")) str))
        )
    )
 )
 (princ)
)

 

HTH

Posted

Works perfect pBe, thx for the help

 

now gonna try to take your extra code and learn something from it.

that mapcar lamda is not that easy.

 

thx again,

greetz John

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