Jump to content

please help... convert POLYLINES  into a blockS


Recommended Posts

Posted (edited)

Hi all please help
I have multiple  POLYLINES  that are the same
I want to convert it into a block with the same name
Thanks in advance

 

 

Capture.JPG

RECCDrawing4.dwg

Edited by hosneyalaa
Posted

Easier way is to select them and copy with base point and paste as block. :)

Posted
5 minutes ago, Trudy said:

Easier way is to select them and copy with base point and paste as block. :)

 

 

I want every POLYLINE AS block 
All blocks have the same name
Until
If you change any block for example, add a point
It applies to all

Posted

Auto Cad:

 

1 - Select all polylines

2 - Press at once: Ctrl+Shift+C

3 - Choose a base point with your mouse

4 - Press at once: Ctrl+Shift+V

 

If You want them back to polyline:

 

1 - Select the block

2 - Type in the command bar: expload

 

I hope I helped!

 

 

 

  • Thanks 1
Posted
6 hours ago, marko_ribar said:

If you have BricsCAD, look for command BLOCKIFY, or if you are using AutoCAD and can log to www.theswamp.org, you have my set of block routines similar to BLOCKIFY... Here is the link :

http://www.theswamp.org/index.php?topic=55186.0

 

hi marko_ribar 

I didn't know how to apply the idea
Can you work for me

Posted (edited)

I found this code
But each  polyline  a block  differently

 


;  https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-multiple-lines-to-block/td-p/6794769



(defun C:P2B (/ ss base n blk pl); = Polylines [to] Blocks
  (if (setq ss (ssget '((0 . "*POLYLINE"))))
    (progn ; then
    (setq base 0)
    (while (tblsearch "block" (strcat "P2B" (itoa (1+ base))))
      (setq base (1+ base))
    ); while
    (repeat (setq n (sslength ss))
      (setq
    pl (ssname ss (setq n (1- n)))
    corners
      (list
        (setq v1 (vlax-curve-getPointAtParam pl 0))
        (vlax-curve-getPointAtParam pl 1)
        (setq v3 (vlax-curve-getPointAtParam pl 2))
        (vlax-curve-getPointAtParam pl 3)
      ); list
    midpt (mapcar '/ (mapcar '+ v1 v3) '(2 2 2))
  )
      (command
        "_.block" (setq blk (strcat "P2B" (itoa (+ base n)))); increment Block name
          "_none" midpt
          pl ""
        "_.insert" blk "_none" "@" "" "" ""
      ); command
    ); repeat
    ); progn
  ); if
); defun

 

التقاط.PNG

Edited by hosneyalaa
Posted

I have cut this out of some code I just did and its a starting point you would pick all rectangs use  this method and make a list of entity name and d1 d2 Y (-1 . <Entity name: 3e66fd20>) sort the list and you should have a list of common size rectangs in sequence. 

 

(100 200 Entity name: 3e66fd20>)

(100 200 Entity name: 3e66fd21>)

(100 200 Entity name: 3e66fd22>)

 

replace entsel with ssget and use a repeat and ssname to go through selection

(setq plent  (entsel "Pick obj"))
(if (= (cdr (assoc 0 (entget (car plent)))) "LWPOLYLINE")
(progn
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent)))))
(setq pt1 (nth 0 co-ord))
(setq pt2 (nth 1 co-ord))
(setq pt3 (nth 2 co-ord))
(setq pt4 (nth 3  co-ord))
(setq d1 (distance pt1 pt2))
(setq d2 (distance pt2 pt3))
(if (< d1 d2) swap to make say shortest 1st
 do your thing and make a list
))
sort list
repeat
make a block 1st rectang using d1 d2
insert at nth 0 co-ord angle is 1st -> 2nd point

 

  • Thanks 1
Posted (edited)

just FYI You should avoid lisp that uses increment block naming because you will run into naming conflicts if you ever try to combine two drawings together. well not really conflicts if the blocks are not the same it will change to the block the drawing you are pasting into.

 

Example.

Drawing 1 has P2B1 block its a circle.

Drawing 2 has P2B1 block its a rectangle.

if you copy P2B1 from Drawing1 and paste it into Drawing 2 it will be a rectangle because that is what is defined in Drawing 2 as P2B1. AutoCAD does this all automatically so if you are not paying attention you will miss it.

 

 

look at this for random name generating. or add the drawing name into the block name

Drawing1-P2B1

Drawing2-P2B1

 

 

Edited by mhupp
  • Thanks 1
Posted

It would make sense to me that the blocks are called 36x24rec 18x9rec 

 

If dont want blocks can add xdata to each rectang 

 

To hosneyalaa the important question is why is to just do block counting ? You could do rectang size counting.

  • Thanks 1
Posted

@BIGAL  ,  marko_ribar ,  mhupp  ,  Trudy

 

 

Thanks to all
Please take a look at the code
Is it good
I hope you improve if possible

 

 




(defun C:testP2B (/ ss base n blk pl ANG ANG0 AUNITSS MIDPT MIDPT0 PL0)

(SETQ AUNITSS (GETVAR "AUNITS"))
(SETVAR "AUNITS" 3)
  
  
  (if (setq ss (ssget  '((0 . "*POLYLINE"))))
    (progn ; then
    (setq pl0 (ssname ss 0))
    (setq midpt0 (vlax-curve-getStartPoint pl0))
    (setq
  ang0
    (angle
      '(0 0 0)
      (vlax-curve-getFirstDeriv
        pl0
        0 
      ); end 1st deriv
    ); end angle & ang
)
    
    (if (not (tblsearch "block" "P2B"))

      (command
        "_.block" "P2B"
          "_none" midpt0
          pl0 ""
        "_.insert" "P2B" "_none" "@" "" "" (rtos ang0 2 3)
      )
      
      )

 (setq n 0)
    (repeat (- (sslength ss) 1)
      (setq n (+ 1 n))
      (setq pl (ssname ss n))
      (setq midpt (vlax-curve-getStartPoint pl))
      (setq
  ang
    (angle
      '(0 0 0)
      (vlax-curve-getFirstDeriv
        pl
        0 
      ); end 1st deriv
    ); end angle & ang
)

      
      
      (command "_.insert" "P2B" midpt 1 1 (rtos (- ang ang0) 2 3))

      
    ); repeat
    
    ); progn
  ); if


(SETVAR "AUNITS" aunitss)
  
  
); defun

   

    

 

Capture.JPG

Posted (edited)

If you want my routines to work for you, you must set AUNITS = 0... If you want to convert single unit curves to blocks, you can use (c:curv2blk) if all are placed in WCS and they all define UCS=WCS (means they are planar), or (c:curv2blk-3d) if they are scattered in 3D no matter what UCS is active or if curve define UCS in 3D... My BLOCKIFY version (c:blockify) works with many curves, but all must belong to same UCS in 3D and they all are planar (define the same UCS in 3D)...

Edited by marko_ribar
  • Thanks 1

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