Simple VLAX block object insertion problem

Simple VLAX block object insertion problem

Anonymous
Not applicable
1,424 Views
3 Replies
Message 1 of 4

Simple VLAX block object insertion problem

Anonymous
Not applicable

Hi All,

 

I have only started learning to use LISP and it has been a bit of a learning curve. I have successfully made a program that inserts different blocks at different coordinates which increment. Now I want to change attributes in those blocks as they are inserted so I have gone from the simple block command to needing a vla object in which I can later use in a loop with 'getattributes.  I have a block in the drawing called "myblock". When I run the following code, I get ; error: Exception occurred. 

 

(defun c:vlaxtester (/ cur_pos blk testblock)
  (vl-load-com)
  (setq testblock "myblock")
  (setq cur_pos (vlax-3d-point 0 10000 0))
  (setq blk (vlax-invoke (vlax-get (vla-get-ActiveLayout (vla-get-activedocument (vlax-get-acad-object))) 'Block) 'InsertBlock cur_pos testblock 1 1 1 0))
) 

I have also tried calling the vlax-get function separately which works, and then incorporating it into the vlax-invoke function at which point it fails with the above general exception. I have been searching everywhere and see people using what looks like what i have above. I have tried the function insertion point as a 3 element list and the block name as the string "myblock"

 

Any help would be appreciated, I am feeling it is possible I am conceptually misunderstanding this.

0 Likes
Accepted solutions (1)
1,425 Views
3 Replies
Replies (3)
Message 2 of 4

dbhunia
Advisor
Advisor
Accepted solution

Try like this.......

 

(defun c:vlaxtester (/ cur_pos blk testblock)
	(vl-load-com)
	(setq testblock "myblock")
	(setq cur_pos (list 0.0 10000.0 0.0))
	(setq blk (vlax-invoke
				(vlax-get
					(vla-item
						(vla-get-layouts
							(vla-get-activedocument
								(vlax-get-acad-object)
							)
						)
						"MODEL"
					)
					'block
				)
				'InsertBlock
				cur_pos
				testblock
				1
				1
				1
				0
			   )
	)
) 

 

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 3 of 4

Sea-Haven
Mentor
Mentor

This is a direct copy from Autodesk forum a quick google

 

(setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
   
    ;; Insert the block
    (setq insertionPnt (vlax-3d-point 2 2 0))
    (setq modelSpace (vla-get-ModelSpace doc))
    (setq blockRefObj (vla-InsertBlock modelSpace insertionPnt "CircleBlock" 1 1 1 0))
0 Likes
Message 4 of 4

Anonymous
Not applicable

Thankyou so much dbhunia! Works perfectly, i really need to do a lot more learning.

And  sea.haven thanks for showing the google search you received, I think my search terms weren't up to scratch on this one.

0 Likes