Jump to content

ActiveX Server returned the error: unknown name: "GETATTRIBUTES"


Recommended Posts

Posted

I am writing lisp to paste object length to attribute with tag "LEN". I wrote this code:

(defun c :ptv (/ reb mrk fm)
  (setq fm "%lu2%pr0")
  (setq reb (vla-get-objectid (vlax-ename->vla-object (car (nentsel "\nSelect the Rebar: ")))))
  (setq reb (strcat "%<\\AcObjProp Object(%<\\_ObjId "(itoa reb)">%).Length \\f " fm ">%"))
  (setq len "LEN")
  (setq reb (list (cons len reb)))
  (setq mrk (entget (car (nentsel "\nPick the Mark: "))))
  (setq mrk (vlax-ename->vla-object (cdr (assoc 330 mrk))))
  (LM:setattributevalues mrk reb)
  (command "regen")
);defun

(defun LM:setattributevalues ( blk lst / itm )
    (foreach att (vlax-invoke blk 'getattributes)
        (if (setq itm (assoc (vla-get-tagstring att) lst))
            (vla-put-textstring att (cdr itm))
        )
    )
)
 

When I run this lisp I get that error when I click on block. But this code run perfectly when I click on the attribute in the block. Please help me to correct this code.

Posted (edited)

Not sure what you're copying, but if the problem is just pasting to a block (attribute "LEN"), then try this

 

 (defun c:ptv (/ reb mrk fm len)
  (setq fm "%lu2%pr0")
  (setq reb (vla-get-objectid (vlax-ename->vla-object (car (nentsel "\nSelect the Rebar: ")))))
  (setq reb (strcat "%<\\AcObjProp Object(%<\\_ObjId "(itoa reb)">%).Length \\f " fm ">%"))
  (setq len "LEN")
  (setq reb (list (cons len reb)))
 
  ;; These two lines let the client select a subentity (nentsel).
    ;;(setq mrk (entget (car (nentsel "\nPick the Mark: "))))
  ;; This second line then searches for the parent    (of the attribute)
    ;;(setq mrk (vlax-ename->vla-object (cdr (assoc 330 mrk))))
 
  ;; instead this line lets the user select the block itself (entsel) instead of (nentsel)
  (setq mrk (vlax-ename->vla-object  (car  (entsel "\nPick the Mark: "))))
 
  (LM:setattributevalues mrk reb)
  (command "regen")
)  ;defun

(defun LM:setattributevalues ( blk lst / itm )
    (foreach att (vlax-invoke blk 'getattributes)
        (if (setq itm (assoc (vla-get-tagstring att) lst))
            (vla-put-textstring att (cdr itm))
        )
    )
)

Edited by Emmanuel Delay
  • Thanks 1
Posted (edited)
11 hours ago, votuanh said:

I am writing lisp to paste object length to attribute with tag "LEN". I wrote this code:

(defun c :ptv (/ reb mrk fm)
  (setq fm "%lu2%pr0")
  (setq reb (vla-get-objectid (vlax-ename->vla-object (car (nentsel "\nSelect the Rebar: ")))))
  (setq reb (strcat "%<\\AcObjProp Object(%<\\_ObjId "(itoa reb)">%).Length \\f " fm ">%"))
  (setq len "LEN")
  (setq reb (list (cons len reb)))
  (setq mrk (entget (car (nentsel "\nPick the Mark: "))))
  (setq mrk (vlax-ename->vla-object (cdr (assoc 330 mrk))))
  (LM:setattributevalues mrk reb)
  (command "regen")
);defun

(defun LM:setattributevalues ( blk lst / itm )
    (foreach att (vlax-invoke blk 'getattributes)
        (if (setq itm (assoc (vla-get-tagstring att) lst))
            (vla-put-textstring att (cdr itm))
        )
    )
)
 

When I run this lisp I get that error when I click on block. But this code run perfectly when I click on the attribute in the block. Please help me to correct this code.

 

The obvious answer is  :

 

You are not passing a block with attributes and/or that you are not passing a dotted pair list of tags and values to the (LM:setattributevalues) function. See Lee's documentation below

 

;; Set Attribute Values  -  Lee Mac
;; Sets attributes with tags found in the association list to their associated values.
;; blk - [vla] VLA Block Reference Object
;; lst - [lst] Association list of ((<tag> . <value>) ... )
;; Returns: nil

(defun LM:vl-setattributevalues ( blk lst / itm )
    (foreach att (vlax-invoke blk 'getattributes)
        (if (setq itm (assoc (vla-get-tagstring att) lst))
            (vla-put-textstring att (cdr itm))
        )
    )
)

 

Edited by dlanorh
  • Thanks 1
Posted

There are many issues with your current code - you'll need to:

  • Account for null user input for selection of both the source object & destination
  • Check whether the selected source object has a Length property
  • Check whether the selected destination object is an attributed block
  • Account for 32-bit & 64-bit OS & applications when obtaining the ObjectID

It's probably easier for you to create a custom program to call my Length Field function.

  • Thanks 1
Posted

Thank you guys for your help. The Emmanuel Delay’s code is working well. And thank Lee Mac for your subprogram.

On 11/16/2018 at 3:39 PM, Emmanuel Delay said:

Not sure what you're copying, but if the problem is just pasting to a block (attribute "LEN"), then try this

 


 (defun c:ptv (/ reb mrk fm len)
  (setq fm "%lu2%pr0")
  (setq reb (vla-get-objectid (vlax-ename->vla-object (car (nentsel "\nSelect the Rebar: ")))))
  (setq reb (strcat "%<\\AcObjProp Object(%<\\_ObjId "(itoa reb)">%).Length \\f " fm ">%"))
  (setq len "LEN")
  (setq reb (list (cons len reb)))
 
  ;; These two lines let the client select a subentity (nentsel).
    ;;(setq mrk (entget (car (nentsel "\nPick the Mark: "))))
  ;; This second line then searches for the parent    (of the attribute)
    ;;(setq mrk (vlax-ename->vla-object (cdr (assoc 330 mrk))))
 
  ;; instead this line lets the user select the block itself (entsel) instead of (nentsel)
  (setq mrk (vlax-ename->vla-object  (car  (entsel "\nPick the Mark: "))))
 
  (LM:setattributevalues mrk reb)
  (command "regen")
)  ;defun

(defun LM:setattributevalues ( blk lst / itm )
    (foreach att (vlax-invoke blk 'getattributes)
        (if (setq itm (assoc (vla-get-tagstring att) lst))
            (vla-put-textstring att (cdr itm))
        )
    )
)

 

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