Author Topic: Split block crossing by polyline it's possible with lisp?  (Read 3304 times)

0 Members and 1 Guest are viewing this topic.

LULU1965

  • Mosquito
  • Posts: 16
Split block crossing by polyline it's possible with lisp?
« on: December 13, 2016, 09:59:47 AM »
Split block crossing by polyline it's possible with lisp? :evil: :crazy2: :mrgreen:

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Split block crossing by polyline it's possible with lisp?
« Reply #1 on: December 13, 2016, 10:18:32 AM »
Posting the same problem in two forums seems to have become the new standard. :cry:
http://www.cadtutor.net/forum/showthread.php?99247-Split-block-crossing-by-polyline-it-s-possible-with-lisp

ribarm

  • Gator
  • Posts: 3300
  • Marko Ribar, architect
Re: Split block crossing by polyline it's possible with lisp?
« Reply #2 on: December 13, 2016, 10:30:14 AM »
I answered there :

And new reply...
« Last Edit: December 13, 2016, 10:52:02 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

xdcad

  • Swamp Rat
  • Posts: 505
Re: Split block crossing by polyline it's possible with lisp?
« Reply #3 on: November 27, 2023, 11:48:54 PM »
Destroying the original object is not a better way, nor is it universal
You can use the CLIP method of INSERT to create XCLIP


code see:
http://www.theswamp.org/index.php?topic=58796.0
« Last Edit: November 28, 2023, 12:00:16 AM by xdcad »
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net

ribarm

  • Gator
  • Posts: 3300
  • Marko Ribar, architect
Re: Split block crossing by polyline it's possible with lisp?
« Reply #4 on: November 28, 2023, 01:03:28 PM »
Are you creating 2 blocks from 1?
I thought that WIPEOUT will be just enough, just it has to have as boudary 2 parallel polylines connected from bottom and top side... Block should remain untouched with same look...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

xdcad

  • Swamp Rat
  • Posts: 505
Re: Split block crossing by polyline it's possible with lisp?
« Reply #5 on: November 28, 2023, 05:55:34 PM »
Are you creating 2 blocks from 1?
I thought that WIPEOUT will be just enough, just it has to have as boudary 2 parallel polylines connected from bottom and top side... Block should remain untouched with same look...

The original poster did not mean to dig out a strip in the middle.
But a line divides the two parts
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net

ribarm

  • Gator
  • Posts: 3300
  • Marko Ribar, architect
Re: Split block crossing by polyline it's possible with lisp?
« Reply #6 on: November 30, 2023, 01:27:31 PM »
Are you creating 2 blocks from 1?
I thought that WIPEOUT will be just enough, just it has to have as boudary 2 parallel polylines connected from bottom and top side... Block should remain untouched with same look...

The original poster did not mean to dig out a strip in the middle.
But a line divides the two parts

I see that, but what did you do with geometry : create 2 separate blocks, or perform double CLIPIT on invisible boundaries with separational polyline, so that single block parts can move whereever you want...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3300
  • Marko Ribar, architect
Re: Split block crossing by polyline it's possible with lisp?
« Reply #7 on: November 30, 2023, 06:48:43 PM »
So, I did something similar... Here is *.lsp and *.gif...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:split-block ( / *error* LM:ssboundingbox process-box box obj sel spc cmd ss sb j e el b1 b2 bound1 bound2 ) ;;; frm, xfrm - global variables
  2.  
  3.     (vl-load-com)
  4.  
  5.     (defun *error* ( m )
  6.         (while (= 8 (logand 8 (getvar 'undoctl)))
  7.             (if command-s
  8.                 (command-s "_.undo" "_e")
  9.                 (vl-cmdf "_.undo" "_e")
  10.             )
  11.         )
  12.         (if xfrm
  13.             (setvar 'xclipframe 0)
  14.         )
  15.         (if frm
  16.             (setvar 'frame 0)
  17.         )
  18.         (if cmd
  19.             (setvar 'cmdecho cmd)
  20.         )
  21.         (prompt "\nUpon finish moving part of block that was separated consider returning back : xfrm variable to (setvar 'xclipframe xfrm) and frm variable to (setvar 'frame frm)...")
  22.         (if m
  23.             (prompt m)
  24.         )
  25.         (princ)
  26.     )
  27.  
  28.     ;; Selection Set Bounding Box  -  Lee Mac
  29.     ;; Returns a list of the lower-left and upper-right WCS coordinates of a
  30.     ;; rectangular frame bounding all objects in a supplied selection set.
  31.     ;; sel - [sel] Selection set for which to return bounding box
  32.  
  33.     (defun LM:ssboundingbox ( sel / idx llp ls1 ls2 obj urp )
  34.         (repeat (setq idx (sslength sel))
  35.             (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))))
  36.             (if (and (vlax-method-applicable-p obj 'getboundingbox)
  37.                      (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list obj 'llp 'urp))))
  38.                 )
  39.                 (setq ls1 (mapcar 'min (vlax-safearray->list llp) (cond (ls1) ((vlax-safearray->list llp))))
  40.                       ls2 (mapcar 'max (vlax-safearray->list urp) (cond (ls2) ((vlax-safearray->list urp))))
  41.                 )
  42.             )
  43.         )
  44.         (if (and ls1 ls2) (list ls1 ls2))
  45.     )
  46.  
  47.     (defun process-box nil
  48.         (if (and (setq sel (ssget "_A" (list (cons 410 (if (= 1 (getvar 'cvport)) (getvar 'ctab) "Model")))))
  49.                  (setq box (LM:ssboundingbox sel))
  50.             )
  51.             (progn
  52.                 (setq spc
  53.                         (if (= 1 (getvar 'cvport))
  54.                             'paperspace
  55.                             'modelspace
  56.                         )
  57.                     )
  58.                 )
  59.                 (if (equal 0.0 (apply '- (mapcar 'caddr box)) 1e-6)
  60.                     (progn
  61.                         (setq obj
  62.                             (vlax-invoke spc 'addlightweightpolyline
  63.                                 (apply 'append
  64.                                     (mapcar '(lambda ( x ) (mapcar '(lambda ( y ) ((eval y) box)) x))
  65.                                        '(
  66.                                             (caar   cadar)
  67.                                             (caadr  cadar)
  68.                                             (caadr cadadr)
  69.                                             (caar  cadadr)
  70.                                         )
  71.                                     )
  72.                                 )
  73.                             )
  74.                         )
  75.                         (vla-put-closed obj :vlax-true)
  76.                         (vla-put-elevation obj (caddar box))
  77.                     )
  78.                     (apply 'vlax-invoke
  79.                         (vl-list* spc 'addbox
  80.                             (apply 'mapcar (cons '(lambda ( a b ) (/ (+ a b) 2.0)) box))
  81.                             (apply 'mapcar (cons '- (reverse box)))
  82.                         )
  83.                     )
  84.                 )
  85.                 box
  86.             )
  87.         )
  88.     )
  89.  
  90.     (setq cmd (getvar 'cmdecho))
  91.     (setvar 'cmdecho 0)
  92.     (setq xfrm (getvar 'xclipframe))
  93.     (setvar 'xclipframe 0)
  94.     (setq frm (getvar 'frame))
  95.     (setvar 'frame 0)
  96.     (while (= 8 (logand 8 (getvar 'undoctl)))
  97.         (vl-cmdf "_.undo" "_e")
  98.     )
  99.     (vl-cmdf "_.undo" "_be")
  100.     (setq box (process-box))
  101.     (setq el (entlast))
  102.     (prompt "\nPick division LINE, LWPOLYLINE, POLYLINE, SPLINE, ELLIPTIC ARC, ARC, or any open curve that passes desired block that is to be separated...")
  103.     (setq ss (ssget "_+.:E:S:L" '((0 . "*LINE,ELLIPSE,ARC"))))
  104.     (prompt "\nNow select block, hatch and bounding curve that is to be separated through converting to temp block...")
  105.     (setq sb (ssget "_:L" '((0 . "INSERT,HATCH,*LINE,ELLIPSE,ARC,CIRCLE"))))
  106.     (setq j 0)
  107.     (while (and (setq j (1+ j)) (tblsearch "BLOCK" (strcat "X-" (cond ( (< 0 j 10) (strcat "00" (itoa j)) ) ( (< 9 j 100) (strcat "0" (itoa j)) ) ( t (itoa j) ) )))))
  108.     (if command-s
  109.         (command-s "_.BLOCK" (strcat "X-" (cond ( (< 0 j 10) (strcat "00" (itoa j)) ) ( (< 9 j 100) (strcat "0" (itoa j)) ) ( t (itoa j) ) )) "_non" (list 0.0 0.0 0.0) sb "")
  110.         (vl-cmdf "_.BLOCK" (strcat "X-" (cond ( (< 0 j 10) (strcat "00" (itoa j)) ) ( (< 9 j 100) (strcat "0" (itoa j)) ) ( t (itoa j) ) )) "_non" (list 0.0 0.0 0.0) sb "")
  111.     )
  112.     (if command-s
  113.         (command-s "_.INSERT" (strcat "X-" (cond ( (< 0 j 10) (strcat "00" (itoa j)) ) ( (< 9 j 100) (strcat "0" (itoa j)) ) ( t (itoa j) ) )) "_non" (list 0.0 0.0 0.0) 1.0 1.0 0.0)
  114.         (vl-cmdf "_.INSERT" (strcat "X-" (cond ( (< 0 j 10) (strcat "00" (itoa j)) ) ( (< 9 j 100) (strcat "0" (itoa j)) ) ( t (itoa j) ) )) "_non" (list 0.0 0.0 0.0) 1.0 1.0 0.0)
  115.     )
  116.     (setq b1 (entlast))
  117.     (setq b2 (vlax-vla-object->ename (vla-copy (vlax-ename->vla-object b1))))
  118.     (setq e (ssname ss 0))
  119.     (vl-cmdf "_.lengthen" "_de" 5.0 "_non" (trans (vlax-curve-getpointatparam e (+ (vlax-curve-getstartparam e) 0.1)) 0 1))
  120.     (while (< 0 (getvar 'cmdactive))
  121.         (vl-cmdf "")
  122.     )
  123.     (vl-cmdf "_.lengthen" "_de" 5.0 "_non" (trans (vlax-curve-getpointatparam e (- (vlax-curve-getendparam e) 0.1)) 0 1))
  124.     (while (< 0 (getvar 'cmdactive))
  125.         (vl-cmdf "")
  126.     )
  127.     (if (and b1 (not (vlax-erased-p b1)))
  128.         (entdel b1)
  129.     )
  130.     (if (and b2 (not (vlax-erased-p b2)))
  131.         (entdel b2)
  132.     )
  133.     (vl-cmdf "_.-boundary" (mapcar '+ (list 0.1 0.1) (car box)))
  134.     (while (< 0 (getvar 'cmdactive))
  135.         (vl-cmdf "")
  136.     )
  137.     (setq bound1 (entlast))
  138.     (vl-cmdf "_.-boundary" (mapcar '+ (list -0.1 -0.1) (cadr box)))
  139.     (while (< 0 (getvar 'cmdactive))
  140.         (vl-cmdf "")
  141.     )
  142.     (setq bound2 (entlast))
  143.     (if (and b1 (vlax-erased-p b1))
  144.         (entdel b1)
  145.     )
  146.     (if (and b2 (vlax-erased-p b2))
  147.         (entdel b2)
  148.     )
  149.     (vl-cmdf "_.xclip" b1 "" "_n" "_s" bound1)
  150.     (vl-cmdf "_.xclip" b2 "" "_n" "_s" bound2)
  151.     (if (and bound1 (not (vlax-erased-p bound1)))
  152.         (entdel bound1)
  153.     )
  154.     (if (and bound2 (not (vlax-erased-p bound2)))
  155.         (entdel bound2)
  156.     )
  157.     (if (and el (not (vlax-erased-p el)))
  158.         (entdel el)
  159.     )
  160.     (vl-cmdf "_.lengthen" "_de" -5.0 "_non" (trans (vlax-curve-getpointatparam e (+ (vlax-curve-getstartparam e) 0.1)) 0 1))
  161.     (while (< 0 (getvar 'cmdactive))
  162.         (vl-cmdf "")
  163.     )
  164.     (vl-cmdf "_.lengthen" "_de" -5.0 "_non" (trans (vlax-curve-getpointatparam e (- (vlax-curve-getendparam e) 0.1)) 0 1))
  165.     (while (< 0 (getvar 'cmdactive))
  166.         (vl-cmdf "")
  167.     )
  168.     (setvar 'xclipframe 0)
  169.     (vl-cmdf "_.move")
  170.     (while (< 0 (getvar 'cmdactive))
  171.         (vl-cmdf "\\")
  172.     )
  173.     (*error* nil)
  174. )

« Last Edit: December 02, 2023, 04:05:51 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube