Block in table

Block in table

Lex_van_Ham
Advocate Advocate
2,778 Views
13 Replies
Message 1 of 14

Block in table

Lex_van_Ham
Advocate
Advocate

Hello again,

One more question about tables: How do I get a block preview in a table cell.

It doesn't have to be some complicated selection thing just standard always the same block in  the same cell.

Do I just add a line of code in the cell i want it in or is this more complicated? I want it in cell 3 2.

 

(vla-setText table 3 0 "text")
(vla-setText table 3 1)
(   .................      3 2 )

 

Thanks

0 Likes
Accepted solutions (2)
2,779 Views
13 Replies
Replies (13)
Message 2 of 14

_gile
Consultant
Consultant

Hi,

 

As shown in this reply, you can do:

 

(vla-SetBlockTableRecordId table 3 2 blockId :vlax-true)

where blockId is the ObjectId of the block definition.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 14

Lex_van_Ham
Advocate
Advocate

Yeah I got that in it but I don't really know how to get the ID, can you help me with this?

(the blocks aren't drawn but are loaded with the dwt)

0 Likes
Message 4 of 14

Satish_Rajdev
Advocate
Advocate
Accepted solution

Try this functions :

(defun set:tablerecord (tableobject row column blockname / bk fg id)
  (setq	bk (vla-item (vla-get-blocks
		       (vla-get-activedocument (vlax-get-acad-object))
		     )
		     blockname
	   )
  )
  (if (vlax-method-applicable-p
	tableobject
	'setblocktablerecordid32
      )
    (setq id (vla-get-objectid32 bk)
	  fg t
    )
    (setq id (vla-get-objectid bk))
  )
  ((if fg
     vla-setblocktablerecordid32
     vla-setblocktablerecordid
   )
    tableobject	row column id :vlax-true)
)

 

Example :

(set:tablerecord table 3 2 "Specify Blockname")

 

Best Regards,
Satish Rajdev


REY Technologies | Linked IN | YouTube Channel


 

Message 5 of 14

Lex_van_Ham
Advocate
Advocate

Awesome thanks Smiley Happy

0 Likes
Message 6 of 14

_gile
Consultant
Consultant

Here's a way to get the ObjectId of a block which name is bound to the blockName variable.

 

;; get the block table (block definitions collection)
(setq blockTable (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))))
;; get a block by name ;; (throws an error if the the block table does not contain a block names as blockName) (setq block (vla-Item blockTable blockName))
;; get the block ObjectId (setq blockId (vla-get-ObjectId block))

Maybe you want to get all block definitions in the current drawing block table:

 

;; build a list of dotted pairs with all block definitions and their ObjectId
(vlax-for blk blockTable
  (if (and (= (vla-get-IsLayout blk) :vlax-false)
           (= (vla-get-IsXref blk) :vlax-false)
      )
    (setq blockList (cons (cons (vla-get-Name blk) (vla-get-ObjectId blk)) blockList))
  )
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 7 of 14

Lex_van_Ham
Advocate
Advocate

One last thing might be a stupid question but how do I make the text in the entire table larger (within the lisp so without user input)

0 Likes
Message 8 of 14

_gile
Consultant
Consultant

This depends on the current table style settings.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 9 of 14

Satish_Rajdev
Advocate
Advocate

I didn't understand your question, Can you please explain it with picture?

Best Regards,
Satish Rajdev


REY Technologies | Linked IN | YouTube Channel


 

0 Likes
Message 10 of 14

Lex_van_Ham
Advocate
Advocate

When I run the script it makes the table and everything works great but the text is pretty small:

Tiny text.PNG

 

 

 

0 Likes
Message 11 of 14

Satish_Rajdev
Advocate
Advocate
Accepted solution

Understood. You can set text height using this:

(vla-setcelltextheight table row column 1.0)

Best Regards,
Satish Rajdev


REY Technologies | Linked IN | YouTube Channel


 

Message 12 of 14

Lex_van_Ham
Advocate
Advocate

Also, is there a way I can put a .PNG in the cells instead of blocks?

0 Likes
Message 13 of 14

_gile
Consultant
Consultant

You can also set the text height for the entire row:

 

(vla-SetTextHeight table row height)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 14 of 14

_gile
Consultant
Consultant

To be clearer, you can set the text height bay row type:

 

Only data rows (bit 1)

(vla-SetTextHeight table 1 height)

 

Only title row (bit 2)

(vla-SetTextHeight table 2 height)

Only header row (bit 4)

(vla-SetTextHeight table 1 height)

 You can also combinate this, e.g. for the entire table (+ 1 2 4):

(vla-SetTextHeight table 7 height)

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub