Author Topic: Lisp Reading Attributes from a Dynamic block to MLeader  (Read 2472 times)

0 Members and 1 Guest are viewing this topic.

3arizona

  • Mosquito
  • Posts: 2
Lisp Reading Attributes from a Dynamic block to MLeader
« on: April 03, 2020, 12:02:53 PM »
I found this lisp by Lee Mac, from back in 2014.
 
Lisp work perfect. The only issue is, that i have 2 attributes inside my dynamic block and want lisp to read current viability state attribute. Hope this is possible.

Thank you for your time.

 
Code: [Select]

((defun c:mlb ( / at1 at2 ent enx ins lst mld pnt )
    (while
        (progn
            (setvar 'errno 0)
            (setq ent (car (entsel "\nSelect block <exit>: ")))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (null ent)
                    nil
                )
                (   (/= "INSERT" (cdr (assoc 0 (setq enx (entget 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 ent) 'getattributes)
                                  lst (mapcar '(lambda ( x ) (cons (strcase (vla-get-tagstring x)) x)) lst)
                            )
                            (setq at1 (cdr (assoc "STATE-1" lst)))
                            (setq at2 (cdr (assoc "STATE-2" lst)))                           
                        )
                    )
                    (princ "\nBlock does not contain "sate-1\" & \"sate-2\" attributes." at )
                )
                (   (setq ins (cdr (assoc 10 enx))
                          pnt (getpoint (trans ins 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 ent 0) (trans pnt 1 0))
                            0
                        )
                    )
                    (vla-put-textstring mld
                        (strcat
                            "%<\\AcObjProp Object(%<\\_ObjId "
                            (LM:ObjectID at1)
                            ">%).TextString>% - %<\\AcObjProp Object(%<\\_ObjId "
                            (LM:ObjectID at2)
                            ">%).TextString>%"
                        )
                    )
                    (vla-put-textrotation mld 0.0)
                    (if (<= (car pnt) (car (trans ins 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 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)
« Last Edit: April 20, 2020, 12:01:39 PM by 3arizona »

Rustabout

  • Newt
  • Posts: 135
Re: Lisp Reading Attributes from a Dynamic block to MLeader
« Reply #1 on: April 05, 2020, 11:14:26 PM »
I was almost going to have a crack at this, but barely ran out of time. I would have had to create a "dummy block" which I just wasn't into doing.

I see you're already familiar with Lee Macs routines. On his site he also has a "get dynamic block property value" function:

http://www.lee-mac.com/dynamicblockfunctions.html#getdynamicpropvalue

By viability state you mean visibility state right? I've done something similar before and it worked.

Sorry I'm not of much tangible help. Just thought I'd send some encouragement and let you know that your concept is feasible.


Lee Mac

  • Seagull
  • Posts: 12892
  • London, England
Re: Lisp Reading Attributes from a Dynamic block to MLeader
« Reply #2 on: April 06, 2020, 11:53:32 AM »
I have 2 attributes inside my dynamic block and want lisp to read current viability state attribute.

Could you clarify what you mean by this?

Do you want the program to display the current Visibility State name in addition to the value of two other attributes?

3arizona

  • Mosquito
  • Posts: 2
Re: Lisp Reading Attributes from a Dynamic block to MLeader
« Reply #3 on: April 06, 2020, 01:50:59 PM »
Lee
Sorry, i uploaded the wrong lisp. I have updated it to match my request.

My Dynamic block has two Viability States "State-1" and "State-2".
Each attribute reads current content with a filed reading the length of the fastener if stretched.   If possible i want mleader to read current attribute and update if i switch visibility states.

example attribute:
State1: #12 - 3/4" HWH-SD-TEK
State2: #12 - 3/4" HWH-SD-TEK w/NEO


At the moment it's working but it reads both attributes

Thanks
« Last Edit: April 20, 2020, 12:21:16 PM by 3arizona »