Jump to content

help with enter block attribute in to multileader block attribute


Recommended Posts

Posted (edited)

Hi.

I have a lisp that let me select a block and enter its attribute value to a multileader Mtext (see attached).

I need to to do the same for a multileader with block , i.e:

1. to prompt the user to select a block.

2. select the attribute to use (the lisp prompt the user to select one from 3 attributes).

3. enter this attribute value to the multileader block attribute.

 

* the multileader style is already defined and set to current so no need to set it in the lisp.

 

I saw this topic,

but it is dealing with updating existing multileaders,not creating them.

 

I attached here the lisp I'm using and a sample drawing.

 

any help will be appreciated...

 

thanks,

aridzv.

 

MLeaderWBlTxt1.lsp Drawing1.dwg

Edited by aridzv
Posted

Only suggestion no need to select block go straight to Attribute Look at (Nentsel.

Posted (edited)
4 hours ago, BIGAL said:

Only suggestion no need to select block go straight to Attribute Look at (Nentsel.

 

I search for Nentsel and read about it,

but I don't realy understand how to use it in this case..

 

here is the code I got so far:

(defun c:MLeaderWBlTxt_BL( / tagname ensel entsel obj obj1 tag tagname Val1 att ent ML)

   ;(setq tagname "ITEM_DESCRIPTION")

   (initget "ORDER QUANTITY ITEMDESCRIPTION")
   (if (null (setq tagname (getkword "\nChoose Attribute To Show [ORDER/QUANTITY/ITEMDESCRIPTION] <ITEMDESCRIPTION>: ")))
      (setq tagname "ITEM_DESCRIPTION")
   )
 
   (if (= tagname "ITEMDESCRIPTION") (setq tagname "ITEM_DESCRIPTION"))

 (while 1
   (setq ensel (entsel "\nSelect Block: ")) ;select the block object to copy

   (setq obj (car ensel)) ;set the block object to varaible
   (setq obj1 (vlax-ename->vla-object obj)) ;; set the pipe object to a VLAX object for the attribute rotation function

   (setq tag (strcase tagname))
   (setq Val1 (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att))) (vlax-invoke obj1 'getattributes)))
    
   (command "_mleader" pause pause)


   (princ entlast)
   (setq ML (vlax-ename->vla-object (entlast))) ;; set the Mleader object to a VLAX object for the LM:setmleaderblockattributevalue function
   (princ ML)
   ;;(vla-SetBlockAttributeValue ML "ITEM" Val1)
   (LM:setattributevalue ( ML "ITEM" val1 ))
   ;;(setq ent (entlast))
   ;;(setq ent (entsel (entlast)))
   ;;(LM:setmleaderblockattributevalue (ML "ITEM" Val1))
   
 );end while 
)


;; Set Attribute Value  -  Lee Mac
;; Sets the value of the first attribute with the given tag found within the block, if present.
;; blk - [ent] Block (Insert) Entity Name
;; tag - [str] Attribute TagString
;; val - [str] Attribute Value
;; Returns: [str] Attribute value if successful, else nil.

(defun LM:setattributevalue ( blk tag val / enx )
    (if (and (setq blk (entnext blk)) (= "ATTRIB" (cdr (assoc 0 (setq enx (entget blk))))))
        (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
            (if (entmod (subst (cons 1 val) (assoc 1 (reverse enx)) enx))
                (progn
                    (entupd blk)
                    val
                )
            )
            (LM:setattributevalue blk tag val)
        )
    )
)

;; Set MLeader Block Attribute Value  -  Lee Mac
;; mld - [vla] MLeader object with attributed block content
;; tag - [str] Attribute tag whose value will be modified
;; val - [str] New attribute value

(defun LM:setmleaderblockattributevalue ( mld tag val )
   (if (= acblockcontent (vla-get-contenttype mld))
       (vl-catch-all-error-p
           (vl-catch-all-apply
              '(lambda ( / oid )
                   (vlax-for obj
                       (vla-item
                           (vla-get-blocks (vla-get-document mld))
                           (vla-get-contentblockname mld)
                       )
                       (if (and (= "AcDbAttributeDefinition" (vla-get-objectname obj))
                                (= :vlax-false (vla-get-constant obj))
                                (= (strcase tag) (strcase (vla-get-tagstring obj)))
                           )
                           (progn
                               (if (vlax-property-available-p obj 'objectid32)
                                   (setq oid (vla-get-objectid32 obj))
                                   (setq oid (vla-get-objectid   obj))
                               )
                               (if (vlax-method-applicable-p mld 'setblockattributevalue32)
                                   (vla-setblockattributevalue32 mld oid val)
                                   (vla-setblockattributevalue   mld oid val)
                               )
                               (exit)
                           )
                       )
                   )
               )
           )
       )
   )
)

 

and the error it raise:

; ----- LISP : Call Stack -----
; [0]...C:MLEADERWBLTXT_BL <<--
;
; ----- Error around expression -----
; (ML "ITEM" VAL1)

 

what I do wrong?

 

thanks,

aridzv.

 

*EDIT:

I forgot to write that I set those varaibles before using the lisp:

1. ATTREQ = 0

2. ATTDIA = 0

 

Drawing3.dwg

Edited by aridzv
Posted (edited)

O.K....

I managed to get the program to work properly.

I have two comments:

1. I used Lee Mac's "LM:setmleaderblockattributevalue" function,

    but for some reason it didn't work as a function - when I tried to call it the llisp failed,

    so I moved it inside the lisp,And that's the only way I was able to get it to work.

2. I know the code is clumsy, so I would appreciate any comments and suggestions for improvement.

 

aridzv 

 

 

MLeaderWBlTxt_BL1.lsp

Edited by aridzv
Posted

You can call some one else's code into yours very easy. This example is load my Multi getvals.lsp so the program can be called.

 

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq ans (AH:getvalsm (list "Enter values " "Length " 5 4 "6" "Dia " 5 4 "1" "Offset " 5 4 "6" "Dia " 5 4 "3/4")))

 

So you should have been able to use the same method with Lee's code I know have done at times.

Posted
25 minutes ago, BIGAL said:

You can call some one else's code into yours very easy. This example is load my Multi getvals.lsp so the program can be called.

 

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq ans (AH:getvalsm (list "Enter values " "Length " 5 4 "6" "Dia " 5 4 "1" "Offset " 5 4 "6" "Dia " 5 4 "3/4")))

 

So you should have been able to use the same method with Lee's code I know have done at times.

 

I called functions in the past including Lee Mac's functions.

That why it was strange to me that in this case it failed.

Lee Mac's "LM:setmleaderblockattributevalue" function call for multileader object as VLA object and ML is a VLA object,

then it calls for tag wich is a string - I passed "ITEM" - it is a string,

and then ask for the value - Val1 wich is a string.

 

so I can't realy put my finger on why it is not working as an external function...

Posted

Just a maybe, look at start of code for a typo. Rather than tell you what I think is wrong we all have to debug our code every now and then when it does not work.

 

Big Hint Lee's code  ;; val - [str] New attribute value

Posted
14 hours ago, BIGAL said:

Big Hint Lee's code  ;; val - [str] New attribute value

 

@BIGAL

I verified again that var1 is a string.

the strange thing is that when I use the function as part of the lisp code it is working,and with var1 and the other tow varaibles,

and when I try to call it as a function it is not.

Posted

Hi.

I Accidentally load a slightly different code than I used.
here is the actual code with LM:setmleaderblockattributevalue function,
still getting the error :

; ----- Error around expression -----
; (ML "ITEM" VAL1)

 

this is the code:

(defun c:MLeaderWBlTxt_BL1( / tagname ensel entsel obj obj1 obj2 tag tagname Val1 att ent ML ppp)
(vl-load-com)   
(setvar "CMDECHO" 0)
(setq temperr *error*);;store *error*
(setq *error* trap1);;re-assign *error*

(setvar "ATTDIA" 0)
(setvar "ATTREQ" 0)

   (initget "ORDER QUANTITY ITEMDESCRIPTION ITEMDESCRIPTIONHEB")
   (if (null (setq tagname (getkword "\nChoose Attribute To Show [ORDER/QUANTITY/ITEMDESCRIPTION/ITEMDESCRIPTIONHEB] <ITEMDESCRIPTION>: ")))
      (setq tagname "ITEM_DESCRIPTION")
   )
 
   (if (= tagname "ITEMDESCRIPTION") (setq tagname "ITEM_DESCRIPTION"))

 (while 1
   (setq ensel (entsel "\nSelect Block: ")) ;select the block object to copy

   (setq obj1 (car ensel)) ;set the block object to varaible
   (setq obj2 (vlax-ename->vla-object obj1)) ;; set the pipe object to a VLAX object for the attribute rotation function

   (setq tag (strcase tagname))
   (setq Val1 (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att))) (vlax-invoke obj2 'getattributes)))
   (princ val1)
   (command "_mleader" pause pause)


   ;;(princ entlast)
   (setq ML (vlax-ename->vla-object (entlast))) ;; set the Mleader object to a VLAX object for the LM:setmleaderblockattributevalue function

   (princ ML)

   (LM:setmleaderblockattributevalue ( ML "ITEM" val1 ))

   
 );end while 
(setvar "CMDECHO" 1)
(princ)
);; end c:MLeaderWBlTxt_BL


(defun trap1 (errmsg)					;define function
(command "cmdecho" 0)
(setvar "ATTDIA" 1)
(setvar "ATTREQ" 1)
(vla-endundomark doc)

	(setq *error* temperr)				;restore *error*
	(prompt "\nResetting System Variables ")
(setvar "CMDECHO" 1)
   (princ)
)



;; Set Attribute Value  -  Lee Mac
;; Sets the value of the first attribute with the given tag found within the block, if present.
;; blk - [ent] Block (Insert) Entity Name
;; tag - [str] Attribute TagString
;; val - [str] Attribute Value
;; Returns: [str] Attribute value if successful, else nil.

(defun LM:setattributevalue ( blk tag val / enx )
    (if (and (setq blk (entnext blk)) (= "ATTRIB" (cdr (assoc 0 (setq enx (entget blk))))))
        (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
            (if (entmod (subst (cons 1 val) (assoc 1 (reverse enx)) enx))
                (progn
                    (entupd blk)
                    val
                )
            )
            (LM:setattributevalue blk tag val)
        )
    )
)

;; Set MLeader Block Attribute Value  -  Lee Mac
;; mld - [vla] MLeader object with attributed block content
;; tag - [str] Attribute tag whose value will be modified
;; val - [str] New attribute value

(defun LM:setmleaderblockattributevalue ( mld tag val )
   (if (= acblockcontent (vla-get-contenttype mld))
       (vl-catch-all-error-p
           (vl-catch-all-apply
              '(lambda ( / oid )
                   (vlax-for obj
                       (vla-item
                           (vla-get-blocks (vla-get-document mld))
                           (vla-get-contentblockname mld)
                       )
                       (if (and (= "AcDbAttributeDefinition" (vla-get-objectname obj))
                                (= :vlax-false (vla-get-constant obj))
                                (= (strcase tag) (strcase (vla-get-tagstring obj)))
                           )
                           (progn
                               (if (vlax-property-available-p obj 'objectid32)
                                   (setq oid (vla-get-objectid32 obj))
                                   (setq oid (vla-get-objectid   obj))
                               )
                               (if (vlax-method-applicable-p mld 'setblockattributevalue32)
                                   (vla-setblockattributevalue32 mld oid val)
                                   (vla-setblockattributevalue   mld oid val)
                               )
                               (exit)
                           )
                       )
                   )
               )
           )
       )
   )
(princ)
)

 

Posted

(LM:setmleaderblockattributevalue ( ML "ITEM" val1 )) is wrong

 

(LM:setmleaderblockattributevalue  ML "ITEM" val1 ) is correct.

Posted
12 hours ago, BIGAL said:

(LM:setmleaderblockattributevalue ( ML "ITEM" val1 )) is wrong

 

(LM:setmleaderblockattributevalue  ML "ITEM" val1 ) is correct.

 

nop...

still the same error...

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