+ Reply to Thread
Page 1 of 4 1 2 3 ... LastLast
Results 1 to 10 of 40
  1. #1
    Junior Member
    Discipline
    Construction
    Using
    AutoCAD 2016
    Join Date
    Dec 2017
    Posts
    13

    Default Split Block Based on Polylines inside

    Registered forum members do not see this ad.

    Hi guys after nearly 1 month searching, reading and coding I kind of gave up, and just signed up for an account here seeking for some help, any advice would be much appreciated !!

    What I've been trying to do is to split a block based on the small polyline rectangles inside, the closed polylines/rectangles are of same size. Any attributes tags contained within one rectangle should be created as one block at the same location. At the end, a numbers of smaller blocks will replace the old single block.

    For example below I want to convert this single block (attached) to 6 individual blocks with attributes, tags updated for each:
    Drawing1.dwg

    Initially my idea was to separate them based on entities inside, I tried writing some lisp using nentsel, entnext, burst, insert, but didn't work well as I have thousands of blocks like this, sometimes 6 combined into one, sometimes 3 together, and entities were not always created from top to bottom in the data base. That's why I start to look into "polylines", but don't know how to make it work, as I am just a beginner in autolisp

    Please help !

  2. #2
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,890

    Default

    Using this

    Code:
    (setq obj (vlax-ename->vla-object (car (entsel))))
    (vla-GetBoundingBox obj 'minpoint 'maxpoint)
    (setq minpt (vlax-safearray->list  minpoint))
    (setq maxpt (vlax-safearray->list  maxpoint))
    This finds the corners of the block. Then burst the block. Using the co-ords can make a selection set of the polylines, then find the text inside.

    So now make a block of the pline with the text as attributes say tag1 tag2 etc and fill in the attribute values to the text value.

    Phew !

    Need lots of code in between.

    A start.
    Code:
    (setq sspl (ssget "CP" (list minpt maxpt)))
    Code:
    ; Text in polygons
    ; By Alan H may 2013
    (vl-load-com)
    (defun getcoords (ent)
      (vlax-safearray->list
        (vlax-variant-value
          (vlax-get-property
        (vlax-ename->vla-object ent)
        "Coordinates"
          )
        )
      )
    )
     
    (defun co-ords2xy ()
    ; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
    (setq numb (/ (length co-ords) 2))
    (setq I 0)
    (repeat numb
    (setq xy (list (nth I co-ords)(nth (+ I 1) co-ords) ))
    (setq coordsxy (cons xy coordsxy))
    (setq I (+ I 2))
    ) ; end repeat
    ) ; end defun
    
    
    ; program starts here
    ; choose output file change acdatemp to what you want
    (setq fname (strcat "c:/alan/" (getstring "\nEnter file name ")))
    (setq fout (open fname "w"))
    (setq plobjs (ssget (list (cons 0 "lwpolyline"))))
    (setq numb1 (sslength plobjs))
    (setq x numb1)
    (repeat numb1
    (setq obj (ssname plobjs (setq x (- x 1))))
    (setq co-ords (getcoords obj))
    (co-ords2xy)
    ; write pline co-ords here
    (setq numb3 (length co-ords))
    (setq z numb3)
    (setq ansco-ords "")
    (repeat numb3 
    (setq ansco-ords (strcat ansco-ords (rtos (nth (setq z (- z 1)) co-ords) 2 3 ) " " ))
    )
    (setq ans (strcat "Pline " ansco-ords))
    (write-line ans fout)
    (setq ansco-ords "")
    (setq ss (ssget "WP" coordsxy (list (cons 0 "Text,Mtext")))) ; selection set of text within polygon
    (if (= ss nil) 
    (princ "\nnothing inside")
    (progn 
    (setq coordsxy nil) ; reset for next time
    (setq numb2 (sslength ss))
    (setq y numb2)
    (repeat numb2
    (setq anstext (vlax-get-property (vlax-ename->vla-object (ssname ss (setq y (- y 1)))) "Textstring"))
    (princ anstext) ; change to write text to file
    (write-line (strcat "text " anstext) fout)
    (princ "\n")
    ) ; end repeat2
    (setq ss nil) ; reset for next poly
    )
    )
    ) ; end repeat1
    (close fout)
    (princ)
    A man who never made mistakes never made anything

  3. #3
    Junior Member
    Discipline
    Construction
    Using
    AutoCAD 2016
    Join Date
    Dec 2017
    Posts
    13

    Default

    Hi BIGAL, thanks for the reply

    But I tried vla-GetBoundingBox and returned "nil"

    Any ideas ?

  4. #4
    Junior Member
    Discipline
    Construction
    Using
    AutoCAD 2016
    Join Date
    Dec 2017
    Posts
    13

    Default

    In the DWG attached, the small polyline rectangles were inside the block, which means normally we would have to open block editor to be able to select them, the difficulty for me is to obtain these rectangles, then select attributes bound by each rectangle and make a new block.

  5. #5
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,890

    Default

    This finds the corners of the block
    Pick block. I tested on your dwg. Then use burst. Reread the steps in my post.
    A man who never made mistakes never made anything

  6. #6
    Senior Member
    Using
    AutoCAD 2009
    Join Date
    Oct 2012
    Posts
    303

    Default

    nosscc
    Attach an example final result.

  7. #7
    Super Member
    Using
    not applicable
    Join Date
    Jun 2016
    Posts
    588

    Default

    If the rectangles in the blocks are always the same, and the number of attributes per rectangle is fixed the algorithm could be much simpler.

    Select all inserts based on a name and/or layer filter.
    Iterate over the selection set.
    For each existing insert:
    • Collect the attribute values in a list.
    • Based on that list insert one or more new standard blocks and fill out the attributes.
    • Erase the original insert.
    BricsCAD 16

  8. #8
    Junior Member
    Discipline
    Construction
    Using
    AutoCAD 2016
    Join Date
    Dec 2017
    Posts
    13

    Default

    Hi Maratovich, attached here an example result

    Example Result.dwg

  9. #9
    Junior Member
    Discipline
    Construction
    Using
    AutoCAD 2016
    Join Date
    Dec 2017
    Posts
    13

    Default

    Hi Roy

    The problem is how we collect attributes bound by each rectangle within the block ?

    See the example result here Example.dwg

    I did this use some code manually, first I selected the big combined block, then I bursted it, then again I use codes below I manually window selected the first rectangle and attributes, to convert these text to attributes. Then again I select those attributes and type command "block" to make a new block. How do we automate this for 5000 combined blocks in a drawing ?



    (defun c:txt2att ( / el i ss st bk ) (vl-load-com)
    ;(setq bk (ssget '((0 . "INSERT")) ))
    ;(c:BURST)

    (if (setq ss (ssget "_:L" '((0 . "TEXT")))) ; "_:L" reject entities on locked layers
    (repeat (setq i (sslength ss))
    (setq el (entget (ssname ss (setq i (1- i))))
    st (vl-string-translate " " "_" (cdr (assoc 1 el)))
    ) ;end of setq



    (if (and (equal (strlen st) 11) (vl-string-search "-" st))
    (setq st "SOR")
    (setq st "QTY")
    ) ; end of if



    (entmakex
    (append '((0 . "ATTDEF"))
    (vl-remove-if '(lambda ( pair ) (member (car pair) '(0 100 73))) el) ;end of vl-re
    (list
    (cons 70 0)
    (cons 74 (cdr (assoc 73 el)))
    (cons 2 st)
    (cons 3 st)
    )
    )
    ) ; end of entmakex
    (entdel (cdr (assoc -1 el))) ;end of this line

    ) ; end of repeat
    ) ;end of if
    (princ)
    )

  10. #10
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,890

    Default

    Registered forum members do not see this ad.

    Maratovich look at 1st post dwg and final.

    Nosscc have a look at this image I am trying to explain the sequence.
    Attached Images
    A man who never made mistakes never made anything

Similar Threads

  1. Select Polylines in clockwise order from outside to inside
    By broncos15 in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 8th Feb 2017, 03:24 am
  2. Filter Polylines based on elevations
    By feargt in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 7
    Last Post: 9th Dec 2016, 05:28 am
  3. Select Polylines based on standard width * dimscale
    By brawleyman in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 4th Apr 2014, 06:08 pm
  4. select all polylines in the drawing based on its property using VBA
    By vivekgrs in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 19th Jan 2009, 05:03 pm
  5. Use a polyline to automatically split other polylines
    By nrschmid in forum AutoLISP, Visual LISP & DCL
    Replies: 9
    Last Post: 24th Sep 2007, 03:38 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts