Author Topic: How to convert a selection set to a bolck with vla method?  (Read 1918 times)

0 Members and 1 Guest are viewing this topic.

taner

  • Guest
How to convert a selection set to a bolck with vla method?
« on: December 10, 2008, 03:13:14 AM »
Dear all,

How to convert a selection set to a bolck with vla method ?

Thanks a lot.

TanEr
« Last Edit: December 10, 2008, 03:24:47 AM by taner »

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: How to convert a selection set to a bolck with vla method?
« Reply #1 on: December 10, 2008, 06:49:41 AM »
Hi,

Here's a way using CopyObjects method.
To create a new block, you have to specify an insertion point too.

Code: [Select]
(defun c:ss2blk (/ ins blk ss lst)
  (setq *acdoc* (vla-get-ActiveDocument (vlax-get-acad-object)))
  (if (ssget)
    (progn
      (setq ins (getpoint "\nInsertion point: "))
      (setq blk (vla-add (vla-get-Blocks *acdoc*)
(vlax-3d-point ins)
"test"
)
      )
      (vlax-for o (setq ss (vla-get-ActiveSelectionSet *acdoc*))
(setq lst (cons o lst))
      )
      (vla-delete ss)
      (vlax-invoke *acdoc* 'CopyObjects lst blk)
    )
  )
  (princ)
)
Speaking English as a French Frog

cjw

  • Guest
Re: How to convert a selection set to a bolck with vla method?
« Reply #2 on: December 10, 2008, 07:43:57 AM »
Hi,

Here's a way using CopyObjects method.
To create a new block, you have to specify an insertion point too.

Code: [Select]
(defun c:ss2blk (/ ins blk ss lst)
  (setq *acdoc* (vla-get-ActiveDocument (vlax-get-acad-object)))
  (if (ssget)
    (progn
      (setq ins (getpoint "\nInsertion point: "))
      (setq blk (vla-add (vla-get-Blocks *acdoc*)
(vlax-3d-point ins)
"test"
)
      )
      (vlax-for o (setq ss (vla-get-ActiveSelectionSet *acdoc*))
(setq lst (cons o lst))
      )
      (vla-delete ss)
      (vlax-invoke *acdoc* 'CopyObjects lst blk)
    )
  )
  (princ)
)

wa...nice work.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to convert a selection set to a bolck with vla method?
« Reply #3 on: December 10, 2008, 09:04:43 AM »
Found this in my lisp collection, don't know the source.
Create the block object & then use the Add method.
This creates the block definition "Test"
Code: [Select]
(defun C:Test  (/ pt0 myBlk myCircle ptLwPl mySquare)
 (vl-load-com)
 (setq pt0 (vlax-3D-Point '(0.0 0.0 0.0)))
 (setq myBlk (vla-Add (vla-Get-Blocks
                       (vla-Get-ActiveDocument
                        (vlax-Get-Acad-Object)))
                      pt0
                      "Test"))
 (setq myCircle (vla-AddCircle myBlk pt0 1.0))
 (setq ptLwPl (vlax-SafeArray-Fill
               (vlax-Make-SafeArray vlax-vbDouble '(0 . 7))
               '(-1.0 -1.0 1.0 -1.0 1.0 1.0 -1.0 1.0)))
 (setq mySquare (vla-AddLightweightPolyline myBlk ptLwPl))
 (vla-Put-Closed mySquare :vlax-True)
 (princ))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: How to convert a selection set to a bolck with vla method?
« Reply #4 on: December 10, 2008, 09:18:41 AM »
Thanks cjw.

Perhaps a sub routine may be more usefull.

Code: [Select]
;;; SelSet2Block (gile)
;;; Create a new block definition
;;;
;;; Arguments
;;; selSet : a selection set (PICKSET)
;;; insPoint : the insertion point (WCS 3d point)
;;; blkName : the block name (STRING)

(defun SelSet2Block (selSet insPoint blkName / block array index)
  (or *acdoc*
      (setq *acdoc* (vla-get-ActiveDocument (vlax-get-acad-object)))
  )
  (setq block (vla-add (vla-get-Blocks *acdoc*)
       (vlax-3d-point insPoint)
       name
      )
index (1- (sslength ss))
array (vlax-make-safearray
vlax-vbObject
(cons 0 index)
      )
  )
  (repeat (1+ index)
    (vlax-safearray-put-element
      array
      index
      (vlax-ename->vla-object (ssname ss index))
    )
    (setq index (1- index))
  )
  (vla-CopyObjects *acdoc* array block)
)
Speaking English as a French Frog

taner

  • Guest
« Last Edit: December 12, 2008, 07:18:54 PM by taner »