Issue MLeader

Issue MLeader

pierre_costeS8GW8
Enthusiast Enthusiast
960 Views
9 Replies
Message 1 of 10

Issue MLeader

pierre_costeS8GW8
Enthusiast
Enthusiast

Hello everyone, s

 

I do have a Lisp from Lee Mac that display as field the ITEM attribute value when the associated block is pointed by a Leader.

 

I have customed a little bit the routine but for a reason i dont understand, the start point of the leader is not the center point of the block.

 

If someone could help me understand and try to fix it if i am not doing things well. 

 

Thank you guys

 

 

 

(defun c:MLeader_ID ( / Attribute_ID block_ent enx ins lst mld pnt )

 

  (defun CLEANROUTINE () ; Reset each liste each time

    (setq lst nil)

  )

        (while

            (progn

                (setvar 'errno 0)

                (setq block_ent (car (entsel "\nSelect block <exit>: ")))

                (cond

                    (   (= 7 (getvar 'errno))

                        (princ "\nMissed, try again.")

                    )

                    (   (null block_ent)

                        nil

                    )

                    (   (/= "INSERT" (cdr (assoc 0 (setq enx (entget block_ent)))))

                        (princ "\nObject is not a block.")

                    )

                    (   (/= 1 (cdr (assoc 66 enx)))

                        (princ "\nBlock is not attributed.")

                    )

                    (   (not

                            (and

                                (setq lst (vlax-invoke (vlax-ename->vla-object block_ent) 'getattributes)

                                      lst (mapcar '(lambda ( x ) (cons (strcase (vla-get-tagstring x)) x)) lst)

                                )

                                (setq Attribute_ID (cdr (assoc "ITEM" lst)))

                            )

                        )

                    )

                    (   (setq ins (cdr (assoc 10 enx))

                              pnt (getpoint (trans ins block_ent 1) "\nPick leader endpoint <exit>: ")

                        )

                        (setq mld

                            (vlax-invoke

                                (vlax-get-property (LM:acdoc)

                                    (if (= 1 (getvar 'cvport))

                                        'paperspace

                                        'modelspace

                                    )

                                )

                                'addmleader

                                (append (trans ins block_ent 0) (trans pnt 1 0))

                                0

                            )

                        )

                        (vla-put-textstring mld

                            (strcat "%<\\AcObjProp Object(%<\\_ObjId " (LM:ObjectID Attribute_ID) ">%).TextString>%"

                            )

                        )

                        (vla-put-textrotation mld 0.0)

                        (if (<= (car pnt) (car (trans ins block_ent 1)))

                            (progn

                                (vla-setdoglegdirection mld 0 (vlax-3D-point (trans '(-1.0 0.0) 1 0 t)))

                                (vlax-invoke mld 'setleaderlinevertices 0 (append (trans ins block_ent 0) (trans pnt 1 0)))

                            )

                            (vla-setdoglegdirection mld 0 (vlax-3D-point (trans '(1.0 0.0) 1 0 t)))

                        )

                        (vla-regen (LM:acdoc) acactiveviewport)

                        t

                    )

                )

            )

        )

        (princ)

    )

       

    ;; ObjectID  -  Lee Mac

    ;; Returns a string containing the ObjectID of a supplied VLA-Object

    ;; Compatible with 32-bit & 64-bit systems

     

    (defun LM:ObjectID ( obj )

        (eval

            (list 'defun 'LM:ObjectID '( obj )

                (if

                    (and

                        (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))

                        (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring)

                    )

                    (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false)

                   '(itoa (vla-get-objectid obj))

                )

            )

        )

        (LM:ObjectID obj)

    )

     

    ;; Active Document  -  Lee Mac

    ;; Returns the VLA Active Document Object

     

    (defun LM:acdoc nil

        (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))

        (LM:acdoc)

    )

     

    (vl-load-com) (princ)

 

 

 

0 Likes
Accepted solutions (2)
961 Views
9 Replies
Replies (9)
Message 2 of 10

rgrainer
Collaborator
Collaborator

Difficult to tell from your image what it is we're looking at. What are all those polygons?
Show us the final version what you want to see and what you are currently getting.

 

0 Likes
Message 3 of 10

pierre_costeS8GW8
Enthusiast
Enthusiast

Polygons are just here to represent generic block, they could be anything else. They have an attribute "ITEM" with a value of '01' for example. Basically the routine is supposed to pick a block, extract a specific attribute value and display it as field into Leader. While the loop is not closed, you can point any blocks as you want. 

But when i point a block the starting point of the leader is placed is 0;0 instead of being centered in the middle of the block or at its surface. The format i am looking for is the one in green and what i have the red one.

 

Other question ... is it possible to place the field into a circle as the example in green ?

0 Likes
Message 4 of 10

komondormrex
Mentor
Mentor
Accepted solution

hey,

check the following

 

(defun c:mleader_attribute_field (/ insert attribute_found attribute_field_string)
	(setq insert (vlax-ename->vla-object (car (entsel "\nPick block reference: "))))
	(if (vl-some '(lambda (attribute) (= "ITEM" (vla-get-tagstring (setq attribute_found attribute)))) (vlax-invoke insert 'getattributes))
		(progn
			(setq attribute_field_string (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa (vla-get-objectid attribute_found)) ">%).TextString>%"))
			(command "_mleader" (getpoint "\nPick mleader arrow point: ") pause attribute_field_string)
		)
		(alert "No \"ITEM\" tag attribute in picked block reference")
	)
	(princ)
)
0 Likes
Message 5 of 10

pierre_costeS8GW8
Enthusiast
Enthusiast

Thank you it is well working, exactly what i was looking for 

0 Likes
Message 6 of 10

komondormrex
Mentor
Mentor

your welcome)

0 Likes
Message 7 of 10

pierre_costeS8GW8
Enthusiast
Enthusiast
This is really good ! Do you know if it is possible to frame the "ITEM" field into a circle ?
0 Likes
Message 8 of 10

komondormrex
Mentor
Mentor
Accepted solution

text frame display maybe be better?

(defun c:mleader_attribute_field (/ insert attribute_found attribute_field_string)
	(setq insert (vlax-ename->vla-object (car (entsel "\nPick block reference: "))))
	(if (vl-some '(lambda (attribute) (= "ITEM" (vla-get-tagstring (setq attribute_found attribute)))) (vlax-invoke insert 'getattributes))
		(progn
			(setq attribute_field_string (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa (vla-get-objectid attribute_found)) ">%).TextString>%"))
			(command "_mleader" (getpoint "\nPick mleader arrow point: ") pause attribute_field_string)
			(vla-put-textframedisplay (vlax-ename->vla-object (entlast)) :vlax-true)
		)
		(alert "No \"ITEM\" tag attribute in picked block reference")
	)
	(princ)
)

 

0 Likes
Message 9 of 10

komondormrex
Mentor
Mentor

otherwise you need to make a balloon mleader style and put an attribute field inside a balloon of mleader created.

0 Likes
Message 10 of 10

pierre_costeS8GW8
Enthusiast
Enthusiast

Yes, it is better, thanks. 

0 Likes