Jump to content

Recommended Posts

Posted

Hi All!

 

How to convert an existing polyline to a (internal) block with VBA?

Posted

Here's a quick LISP to convert Objects to Blocks:

 

(defun c:obj2blk (/ ss bNme i pt ent)
 ;; Lee Mac  ~  11.02.10

 (cond (  (not (setq ss (ssget '((-4 . "<NOT") (0 . "INSERT,POLYLINE,VIEWPORT") (-4 . "NOT>"))))))

       (  (while
            (progn
              (setq bNme (getstring t "\nSpecify Block Name: "))

              (cond (  (not (snvalid bNme))
                       (princ "\n** Invalid Block Name **"))

                    (  (tblsearch "BLOCK" bNme)
                       (princ "\n** Block Already Exists **"))))))

       (  (not (setq i -1 pt (getpoint "\nSpecify Base Point: "))))

       (t (entmake (list (cons 0 "BLOCK") (cons 10 pt) (cons 2 bNme) (cons 70 0)))

          (while (setq ent (ssname ss (setq i (1+ i))))
            (entmake (entget ent))
            (entdel ent))

          (entmake (list (cons 0 "ENDBLK") (cons 8 "0")))
          (entmake (list (cons 0 "INSERT") (cons 2 bNme) (cons 10 pt)))))

 (princ))

Posted

Super, but it isn't good for me... :( only VBA...

Posted

One sequence of events could be:

 

1. Create a new (empty initially) Block with the appropriate name and insertion point.

 

2. Use the CopyObjects method (see Developer Documentation – ActiveX and VBA Reference – Methods – CopyObjects): Where “Object” is the database where the poly currently resides (ModelSpace, Layout Block, etc.), “Objects” would be a variant array holding the poly, “Owner” would be the Block created in the step 1.

 

3. Insert a Block Reference to that Block into the appropriate space.

 

4. Delete initial Polyline, if needed.

Posted
Sub Pline2Block()

Dim objBlock As AcadBlock
Dim oPline As AcadLWPolyline
Dim varPt As Variant
Dim Cordinat As Variant
Dim UpperBoundery As Integer
Dim LowerBoundery As Integer
Dim objBlockName As String
Dim Scf As Double

ThisDrawing.Utility.GetEntity oPline, varPt, "Select polyline"

   Cordinat = oPline.Coordinates

UpperBoundery = UBound(Cordinat)
LowerBoundery = LBound(Cordinat)

Do
   If l > UpperBoundery Then
       Exit Do
   End If

l = l + 1
Loop

With ThisDrawing.Utility
.InitializeUserInput 1
objBlockName = .GetString(True, vbCr & "Enter block name: ")
End With

Set objBlock = ThisDrawing.Blocks.Add(varPt, objBlockName)
   objBlock.AddLightWeightPolyline Cordinat
Scf = 1

ThisDrawing.ModelSpace.InsertBlock varPt, objBlockName, Scf, Scf, Scf, 0

oPline.Delete

End Sub

Sic? :)

Posted

That would be another sequence of events for a LWPoly to BlockRef conversion - nicely done.

 

To accommodate any type of LWPoly, though, the Bulge factors and Open/Close properties should be addressed.

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