Jump to content

Recommended Posts

Posted

I am trying to work on a LISP routine that would create a legend table for the user that has a block with attributes in each . My end goal in mind is to have the user be able to say how many rows they need and then a table will be inserted where each row in column 1 would have a block inserted into it with an attribute corresponding to the row that it is currently in. What I don't know how to do is how to insert a block into the table through LISP and then to change the attribute value. Does anyone have any suggestions on how to accomplish this? Attached is an image that has my end goal in mind.

Table.JPG

Posted

For inserting a block into a table cell, see the count:setblocktablerecord function used by my Block Counter program.

 

For configuring the attributes of a block within a table cell, study the setblockattributevalue/setblockattributevalue32 ActiveX methods.

Posted
For inserting a block into a table cell, see the count:setblocktablerecord function used by my Block Counter program.

 

For configuring the attributes of a block within a table cell, study the setblockattributevalue/setblockattributevalue32 ActiveX methods.

Thanks Lee! I will be studying the block counter code. So after looking at the setblockattributevalue I feel like I understand how it works. My quick code is
(vla-setblockattributevalue table1 tablerowcnt 0 attid tablerowcnt)

Is there anyway to insert a field that references the tablerow, rather than just inserting text that gives the tablerow?

Posted

I have kind of abandoned the field idea because I can't figure out anyway to have the field reference what the cell's row is. Instead I plan on creating another LISP routine that would allow the user to just renumber the whole table. The routine was pretty straightforward to write, however, I am having difficulty figuring out what block is actually stored in the cell A1 so right now the user has to say what block was used in the legend. I have tried making use of the vla-getcellvalue function, but this doesn't return the block value. Is there some other function that would give the block name?

Posted
See this code and maybe this code.
Lee thank you so much! Both those codes were useful! I tried to incorporate your code into mine and I can't get it to work correctly and I get the error "Error: lisp value has no coercion to VARIANT with this type: "SN"" Where SN is the block name. My code is
(defun c:tablerenumberall (/ vblk tabe attid tablerowcnt tablerow *error*)
 (defun *error* (msg)
   (if (not
         (member msg '("Function cancelled" "quit / exit abort"))
       )
     (princ (strcat "\nError: " msg))
   )
 )
 (if (setq tabe (vlax-ename->vla-object (car (entsel "\nSelect table: "))))
   (progn
     (setq vblk (LM:blocknamefromtablecell tabe 1 0))
     (setq tablerowcnt 0)
     (repeat (vla-get-rows tabe)
       (setq tablerow (+ tablerowcnt 1))
       (vla-setblockattributevalue tabe tablerowcnt 0 vblk tablerow)
       (setq tablerowcnt (+ tablerowcnt 1))
     )
   )
 )
 (princ)
)
;; Block Name from Table Cell  -  Lee Mac
;; obj     - [vla] Table Object
;; row/col - [int] Zero-based row & column indexes
(defun LM:blocknamefromtablecell (obj row col / 64p doc)
 (setq 64p (wcmatch (getenv "PROCESSOR_ARCHITECTURE") "*64*")
       doc (vla-get-activedocument (vlax-get-acad-object))
 )
 (eval
   (list 'defun
         'LM:blocknamefromtablecell
         '(obj row col)
         (list 'if
               '(= acblockcell (vla-getcelltype obj row col))
               (list 'vla-get-name
                     (list
                       (if (and 64p (vlax-method-applicable-p doc 'objectidtoobject32))
                         'vla-objectidtoobject32
                         'vla-objectidtoobject
                       )
                       doc
                       (list
                         (if (and 64p (vlax-method-applicable-p obj 'getblocktablerecordid32))
                           'vla-getblocktablerecordid32
                           'vla-getblocktablerecordid
                         )
                         obj
                         row
                         col
                       )
                     )
               )
         )
   )
 )
 (LM:blocknamefromtablecell obj row col)
)

I was able to have it work originally when I supplied the block name though.

Posted

You're welcome :)

 

Note that the ActiveX setblockattributevalue method requires the Object ID of the Attribute Definition corresponding to the attribute whose value is to be modified, not a block name.

Posted
You're welcome :)

 

Note that the ActiveX setblockattributevalue method requires the Object ID of the Attribute Definition corresponding to the attribute whose value is to be modified, not a block name.

Ahh, that makes sense. So tried to correct it using this
      (setq vblk (LM:blocknamefromtablecell tabe 1 0))
     (setq attid (vla-get-objectid vblk))

However, I still get an error. Am I just going about this in the wrong way/ thinking about this incorrectly?

Posted
So tried to correct it using this
      (setq vblk (LM:blocknamefromtablecell tabe 1 0))
     (setq attid (vla-get-objectid vblk))

However, I still get an error. Am I just going about this in the wrong way/ thinking about this incorrectly?

 

Note that my LM:blocknamefromtablecell function will return a string corresponding to the block name inserted in the table cell - the ActiveX objectid method requires a vla-object argument.

 

You will need to iterate over the components of the block definition corresponding to the block name returned by my function, obtain the appropriate attribute definition and then retrieve the Object ID of this object (accounting for 64-bit architecture). This Object ID may then be used with the ActiveX setblockattributevalue/setblockattributevalue32 methods.

Posted
Note that my LM:blocknamefromtablecell function will return a string corresponding to the block name inserted in the table cell - the ActiveX objectid method requires a vla-object argument.

 

You will need to iterate over the components of the block definition corresponding to the block name returned by my function, obtain the appropriate attribute definition and then retrieve the Object ID of this object (accounting for 64-bit architecture). This Object ID may then be used with the ActiveX setblockattributevalue/setblockattributevalue32 methods.

Thanks Lee! That got me going and I got it all figured out now.
  • 3 weeks later...
Posted

So I have been working on some more commands for tables and one that I can't figure out is how to resize each individual row. I know that I can make use of the vla-setrowheight function to change the row height, but what I want to be able to do is to have each row be perfectly fit (just like how in Excel you can double click a row and it compacts down to the minimum size). I can't think of any property that would allow me to do this. It's odd to me that AutoCAD automatically resizes a row when more text is added (ie when a row goes from 2 to 3 lines), but it doesn't do that when a row goes from 3 to 2 lines. Is there any property that would let me do what I am trying to accomplish?

  • 1 month later...
Posted

Hi dear friends,

I'm looking for a lisp that can extract data from block attributes plus one column for auto fill image of blocks.

for example i have some blocks in my drawing to use symbol of something like bolts or etc. and have also attributes used in my drawing that containing info about my objects and finally i need a table to put every info from attributes with their symbols showing in my table too.

I'll be thankful If you could help me.

Best regards

Javid.

 

:)

Posted

Hi Dear Lee,

Would you please help me about my request too?

Posted

Are you wanting all the blocks in the drawing with attributes, or for the user to select each of the blocks?

Posted

Yes It's better users could choose every attributes they need.

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