TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Coder on November 29, 2010, 06:08:24 AM
-
Hello everybody . :-)
Hope that someone could tell me what are the codes for inserting an object to a block.
I am not looking for a complete routine.
Thanks a lot Guys.
-
Hi,
Just consider you block definition as the ModelSpace:
(vla-AddCircle
(vla-Item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) "BlockName")
(vlax-3d-point '(0. 0. 0.))
10.
)
-
Do you like create object in block definition or copy an object to block definition?
If you have block name:
; Get a pointer to block definition by block name
(setq blk-def (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))))
; Add a new AcDbLine object to block definition
(vla-addline blk-def (vlax-3d-point '(0. 0. 0.)) (vlax-3d-point '(10. 10. 10.)))
If you want to copy object, use vla-CopyObjects method
-
The other option is "bedit," if you are using a version which supports that command.
-
Great codes GUYs.
But what about specifying a point at the block and selecting an entity to be inserted to added to it ? :-)
Many thanks for all.
-
Check an Original property of block definition
-
Try this
http://lee-mac.com/addobjectstoblock.html
-
Check an Original property of block definition
Yeah .... This is the main issue of the thread . So how to dig the BD and touring inside ? :-)
Thanks
-
First of all:
(setq
blk_def (vla-item
(vla-get-blocks
(vla-get-activedocument (vlax-get-acad-object))
) ;_ end of vla-get-blocks
((lambda (/ ent)
(setq
ent (vlax-ename->vla-object
(car (entsel "\nSelect a block reference : "))
) ;_ end of vlax-ename->vla-object
) ;_ end of setq
(if (vlax-property-available-p ent 'effectivename)
(vla-get-effectivename ent)
(vla-get-name ent)
) ;_ end of if
) ;_ end of lambda
)
) ;_ end of vla-item
) ;_ end of setq
And then:
(vlax-dump-object blk_def t)
-
So nice .
My main problem is that how to insert the selected entity to the Block at the same location that it is existed in dwg.
Thanks a lot.
-
You can use CopyObjects method:
(vl-load-com)
(defun copy-objects-to-block-definition (block-name obj)
;|
* Copy objects (obj) to a block definition (block-name)
* Call parameters:
block-name block name
obj vla-pointer to object added to block definition
|;
(cond
((and obj (listp obj))
(foreach item obj
(copy-objects-to-block-definition block-name item)
) ;_ end of foreach
)
((= (type obj) 'ename)
(copy-objects-to-block-definition
block-name
(vlax-ename->vla-object item)
) ;_ end of copy-objects-to-block-definition
)
((= (type obj) 'vla-object)
(vla-copyobjects
(vla-get-activedocument (vlax-get-acad-object))
(vlax-make-variant
(vlax-safearray-fill
(vlax-make-safearray vlax-vbobject '(0 . 0))
(list obj)
) ;_ end of vlax-safearray-fill
) ;_ end of vlax-make-variant
(vla-item (vla-get-blocks
(vla-get-activedocument (vlax-get-acad-object))
) ;_ end of vla-get-blocks
block-name
) ;_ end of vla-item
) ;_ end of vla-copyobjects
)
) ;_ end of cond
) ;_ end of defun
But this code could return unexpected result :)
-
Thanks a lot.
I am still in need to know how to insert an object to a block by codes ?
Regards.
-
My main problem is that how to insert the selected entity to the Block at the same location that it is existed in dwg.
http://lee-mac.com/addobjectstoblock.html
^^ Should do what you want
(Thanks Hasan) :-)
-
...
(Thanks Hasan) :-)
:wink:
-
My main problem is that how to insert the selected entity to the Block at the same location that it is existed in dwg.
^^ Should do what you want
Hi Lee.
Your routine is doing very well , but in your routine you used lots of subentities that it needs a long time to make things clear to me to understand.
And that's why I did mention in the begining I am not looking for a complete routine.
So could you please enlighten at the codes that cover my needs over the thread ?
Thanks
-
My main problem is that how to insert the selected entity to the Block at the same location that it is existed in dwg.
^^ Should do what you want
Hi Lee.
Your routine is doing very well , but in your routine you used lots of subentities that it needs a long time to make things clear to me to understand.
And that's why I did mention in the begining I am not looking for a complete routine.
So could you please enlighten at the codes that cover my needs over the thread ?
Thanks
There isn't just one line of code to add objects to the block - else I would have just used one line myself. The objects need to be properly transformed before adding them to the block definition, the methods I use (CopyObjects) have already been discussed in this thead.
-
The objects needs to be properly transformed before adding them to the block definition.
Yeah... what is that transform ( from and where to :-) ) ?
Thanks
-
The objects needs to be properly transformed before adding them to the block definition.
Yeah... what is that transform ( from and where to :-) ) ?
A translation from the object position relative to the selected block in Model/Paperspace, and rotation/scaling to account for block scale & rotation, to the Block Definition Geometry.
-
The objects needs to be properly transformed before adding them to the block definition.
Yeah... what is that transform ( from and where to :-) ) ?
A translation from the object position relative to the selected block in Model/Paperspace, and rotation/scaling to account for block scale & rotation, to the Block Definition Geometry.
Exactly and defintely . :wink:
That's what I would like to know and that's why I started my thread for.
Hope you show me these codes ?
if you do not mind of course .
Appreciated.
-
The objects needs to be properly transformed before adding them to the block definition.
Yeah... what is that transform ( from and where to :-) ) ?
A translation from the object position relative to the selected block in Model/Paperspace, and rotation/scaling to account for block scale & rotation, to the Block Definition Geometry.
Exactly and defintely . :wink:
That's what I would like to know and that's why I started my thread for.
Hope you show me these codes ?
if you do not mind of course .
Appreciated.
I have already shown you the code - it is downloadable from the link provided.