Jump to content

Recommended Posts

Posted

A lot of questions all come at once it seems...

 

I am not entirely confident in using this function, but I want to master it.

 

Currently, when extracting an item from a collection, I am using vlax-for to cycle through the collection, and using some kind of conditional within the loop to get the required object, like:

 

(vlax-for lay (vla-get-layers
               (vla-get-ActiveDocument
                 (vlax-get-acad-object)))
 (if (eq "LayerName" (vla-get-Name lay))
   (setq layer lay)))

 

But is there a way to get at this item directly? I thought perhaps vla-item, but I may be mistaken.

Posted

I think you answered your own question :P. Personally I'd use the tblobjname approach like so:

 

(defun getlayer (name / olyr)
 (if (and (setq olyr (tblobjname "layer" name))
          (setq olyr (vlax-ename->vla-object olyr))
     )
   olyr
 )
)

Posted
I think you answered your own question :P. Personally I'd use the tblobjname approach like so:

 

(defun getlayer (name / olyr)
 (if (and (setq olyr (tblobjname "layer" name))
          (setq olyr (vlax-ename->vla-object olyr))
     )
   olyr
 )
)

 

I suppose that is "cleaner", but I am still intrigued by this "vla-item", how is it used?

Posted

You want something like this Lee?

 

(vla-item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
         "0"
)

Posted
You want something like this Lee?

 

(vla-item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
         "0"
)

 

Ahh, I see thanks Ron - you have been a great help.

 

I read the article in the ACAD help on VLA-Item, and it mentions the index location of the object in the collection - which I did not know how to specify.

 

But you have demonstrated that specifying the layer name will pull it out too. :)

Posted

Thanks for your help - this is really useful, just experimenting, you can cycle through block sub-entities pretty quick:

 

(defun test  (/ lst)
 (vlax-for Obj
   (vla-item
     (vla-get-blocks
       (vla-get-ActiveDocument
         (vlax-get-acad-object))) "blockname")
   (setq lst (cons Obj lst)))
 lst)

 

Cheers Ron :)

 

Lee

  • 8 years later...
Posted (edited)
Thanks for your help - this is really useful, just experimenting, you can cycle through block sub-entities pretty quick:

 

(defun test  (/ lst)
 (vlax-for Obj
   (vla-item
     (vla-get-blocks
       (vla-get-ActiveDocument
         (vlax-get-acad-object))) "blockname")
   (setq lst (cons Obj lst)))
 lst)

 

Cheers Ron :)

 

Lee

 

Can this code work for ObjectDBX method I tried on your ObjectDBX Wrapper function as below but it show error.

 

code is as below

 

(defun LM:DBXAttChange ( dwg lst BlkName / doc flg val )
   (if (setq doc (LM:GetDocumentObject dwg))
       (progn
  (get-item (vla-get-block (vla-get-modelspace doc)) blkname)
           (vlax-for lyt (vla-get-layouts doc)
		  (vlax-for (vla-item obj (vla-get-block lyt) blkname)
                   (if (and (= "AcDbBlockReference" (vla-get-objectname obj))
                            (= :vlax-true (vla-get-hasattributes obj))
                       )..................................

Edited by SLW210
Added Code Tags
Posted

When you use vla-item, you need to specify the name of the specific element

Posted

@DineshPawar:

You need to get better acquainted with the object model.

(defun Test (dwg blkName / doc)
 (setq blkName (strcase blkName))
 (if (setq doc (LM:GetDocumentObject dwg))
   (vlax-for lyt (vla-get-layouts doc)
     (vlax-for obj (vla-get-block lyt)
       (if 
         (and
           (= "AcDbBlockReference" (vla-get-objectname obj))
           (= blkName (strcase (vla-get-effectivename obj)))
           (= :vlax-true (vla-get-hasattributes obj))
         )
         (progn
           ...
         )
       )
     )
   )
 )
)

Posted

@Roy_143, @zixuan203344

Thank you for your help I am tring to implement your suggestion in my code.

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