Jump to content

Recommended Posts

Posted

Hi

 

Would it be possible to create a gap or split on 3d polyline by implementing  nentsel-getreal and gr-osmode in the code ?

 

For example I have 3d polyline and I just want to select two points on 3d polyline to create a gap? Maybe instead of gap, line could still stay if needed?

 

Thank you for your help

 

(vl-load-com)
(defun gr-osmode (pt-i str-md / n pt md rap pt1 pt2 pt3 pt4 pt5 pt6 pt7 pt8 pt56 pt67 pt78 pt85 one_o)
  (setq n (/ (cadr (getvar "screensize")) 5.0))
  (setq pt (osnap pt-i str-md))
  (while (and (eq (strlen (setq md (substr str-md 1 4))) 4) (not one_o))
    (repeat 2
      (setq
        rap (/ (getvar "viewsize") n)
        pt1 (list (- (car pt) rap) (- (cadr pt) rap) (caddr pt))
        pt2 (list (+ (car pt) rap) (- (cadr pt) rap) (caddr pt))
        pt3 (list (+ (car pt) rap) (+ (cadr pt) rap) (caddr pt))
        pt4 (list (- (car pt) rap) (+ (cadr pt) rap) (caddr pt))
        pt5 (list (car pt) (- (cadr pt) rap) (caddr pt))
        pt6 (list (+ (car pt) rap) (cadr pt) (caddr pt))
        pt7 (list (car pt) (+ (cadr pt) rap) (caddr pt))
        pt8 (list (- (car pt) rap) (cadr pt) (caddr pt))
        pt56 (polar pt (- (/ pi 4.0)) rap)
        pt67 (polar pt (/ pi 4.0) rap)
        pt78 (polar pt (- pi (/ pi 4.0)) rap)
        pt85 (polar pt (+ pi (/ pi 4.0)) rap)
        n (- n 16)
      )
      (if (equal (osnap pt-i md) pt) (setq one_o T))
      (cond
        ((and (eq "_end" md) one_o)
          (grdraw pt1 pt2 1) (grdraw pt2 pt3 1) (grdraw pt3 pt4 1) (grdraw pt4 pt1 1)
        )
        ((and (eq "_mid" md) one_o)
          (grdraw pt1 pt2 1) (grdraw pt2 pt7 1) (grdraw pt7 pt1 1)
        )
        ((and (eq "_cen" md) one_o)
          (grdraw pt5 pt56 1) (grdraw pt56 pt6 1) (grdraw pt6 pt67 1) (grdraw pt67 pt7 1) (grdraw pt7 pt78 1) (grdraw pt78 pt8 1) (grdraw pt8 pt85 1) (grdraw pt85 pt5 1)
          (grdraw pt5 pt7 7) (grdraw pt6 pt8 7)
        )
        ((and (eq "_nod" md) one_o)
          (grdraw pt5 pt56 1) (grdraw pt56 pt6 1) (grdraw pt6 pt67 1) (grdraw pt67 pt7 1) (grdraw pt7 pt78 1) (grdraw pt78 pt8 1) (grdraw pt8 pt85 1) (grdraw pt85 pt5 1)
          (grdraw pt1 pt3 1) (grdraw pt2 pt4 1)
        )
        ((and (eq "_qua" md) one_o)
          (grdraw pt5 pt6 1) (grdraw pt6 pt7 1) (grdraw pt7 pt8 1) (grdraw pt8 pt5 1)
        )
        ((and (eq "_int" md) one_o)
          (grdraw pt1 pt3 1) (grdraw pt2 pt4 1)
        )
        ((and (eq "_ins" md) one_o)
          (grdraw pt5 pt2 1) (grdraw pt2 pt6 1) (grdraw pt6 pt8 1) (grdraw pt8 pt4 1) (grdraw pt4 pt7 1) (grdraw pt7 pt5 1)
        )
        ((and (eq "_per" md) one_o)
          (grdraw pt1 pt2 1) (grdraw pt1 pt4 1) (grdraw pt8 pt 1) (grdraw pt pt5 1)
        )
        ((and (eq "_tan" md) one_o)
          (grdraw pt5 pt56 1) (grdraw pt56 pt6 1) (grdraw pt6 pt67 1) (grdraw pt67 pt7 1) (grdraw pt7 pt78 1) (grdraw pt78 pt8 1) (grdraw pt8 pt85 1) (grdraw pt85 pt5 1)
          (grdraw pt3 pt4 1)
        )
        ((and (eq "_nea" md) one_o)
          (grdraw pt1 pt2 1) (grdraw pt2 pt4 1) (grdraw pt4 pt3 1) (grdraw pt3 pt1 1)
        )
      )
    )
    (setq str-md (substr str-md 6) n (/ (cadr (getvar "screensize")) 5.0))
  )
)
(defun nentsel-getreal ( / o mod ent key n nbr)
  (setq o (getvar "osmode"))
  (if (or (zerop o) (eq (boole 1 o 16384) 16384))
    (setq mod "_none")
    (progn
      (setq mod "")
      (mapcar
        '(lambda (xi xs)
          (if (not (zerop (boole 1 o xi)))
            (if (zerop (strlen mod))
              (setq mod (strcat mod xs))
              (setq mod (strcat mod "," xs))
            )
          )
        )
        '(1 2 4 8 16 32 64 128 256 512 2048 4096 8192)
        '("_endp" "_mid" "_cen" "_nod" "_qua" "_int" "_ins" "_per" "_tan" "_nea" "_appint" "_ext" "_par")
      )
    )
  )

 

 

create gap on 3d polyine.JPG

Posted

in python, or .net you can use getSplitCurves

example

 

import traceback
from pyrx_imp import Ap, Db, Ed, Ge, Gi, Gs, Rx

def PyRxCmd_splitit() -> None:
    try:
        db = Db.curDb()
        
        #get the points
        esres = Ed.Editor.entSel("\nSel", Db.Curve.desc())
        pntres1 = Ed.Editor.getPoint("\nPick Point")
        pntres2 = Ed.Editor.getPoint("\nPick Second Point")
        
        #sort the points by distance from start
        split = [pntres1[1], pntres2[1]]
        selectedCurve = Db.Curve(esres[1], Db.OpenMode.kForWrite)
        split.sort(key=lambda x: selectedCurve.getParamAtPoint(x))
        
        #split the curve, dont add the middle section
        for curve in selectedCurve.getSplitCurves(split):
            accur = curve.getAcGeCurve()
            if (accur.getStartPoint() == split[0]
                and accur.getEndPoint() == split[1]):
                continue
            db.addToCurrentspace(curve)
        
        #erase the original
        selectedCurve.erase()

    except Exception as err:
        traceback.print_exception(err)

 

split.png.09c6adef9c178c482b416f1925ec09be.png

Posted

Line Osnap nearest so pick a point, drag a line from that point, Line Osnap nearest draw second line. Trim, pick the dummy 2 lines Enter pick between them and section is trimmed out.

 

image.png.7605b35dcf930e633f39cb62bddd4c3a.png

 

A lisp yes but pretty quick to do manual only thing is lisp deletes dummy lines.

Posted
15 hours ago, Danielm103 said:

in python, or .net you can use getSplitCurves

example

 

import traceback
from pyrx_imp import Ap, Db, Ed, Ge, Gi, Gs, Rx

def PyRxCmd_splitit() -> None:
    try:
        db = Db.curDb()
        
        #get the points
        esres = Ed.Editor.entSel("\nSel", Db.Curve.desc())
        pntres1 = Ed.Editor.getPoint("\nPick Point")
        pntres2 = Ed.Editor.getPoint("\nPick Second Point")
        
        #sort the points by distance from start
        split = [pntres1[1], pntres2[1]]
        selectedCurve = Db.Curve(esres[1], Db.OpenMode.kForWrite)
        split.sort(key=lambda x: selectedCurve.getParamAtPoint(x))
        
        #split the curve, dont add the middle section
        for curve in selectedCurve.getSplitCurves(split):
            accur = curve.getAcGeCurve()
            if (accur.getStartPoint() == split[0]
                and accur.getEndPoint() == split[1]):
                continue
            db.addToCurrentspace(curve)
        
        #erase the original
        selectedCurve.erase()

    except Exception as err:
        traceback.print_exception(err)

 

split.png.09c6adef9c178c482b416f1925ec09be.png

Looks good, but would need lisp code expertise to help.

Posted
14 hours ago, BIGAL said:

Line Osnap nearest so pick a point, drag a line from that point, Line Osnap nearest draw second line. Trim, pick the dummy 2 lines Enter pick between them and section is trimmed out.

 

image.png.7605b35dcf930e633f39cb62bddd4c3a.png

 

A lisp yes but pretty quick to do manual only thing is lisp deletes dummy lines.

yes i knew that, but i am looking for lisp possibility.

Posted

Have a look in Downloads its 1st item. By Marko Ribarm.

Posted
On 24/07/2024 at 06:01, BIGAL said:

Have a look in Downloads its 1st item. By Marko Ribarm.

its not what i was looking for, but thanks.

Posted
On 7/23/2024 at 10:56 PM, pyou said:

yes i knew that, but i am looking for lisp possibility.

 

With this?

(defun draw_pt (pt col / rap)
  (setq rap (/ (getvar "viewsize") 50))
  (foreach n
    (mapcar
      '(lambda (x)
        (list
          ((eval (car x)) (car pt) rap)
          ((eval (cadr x)) (cadr pt) rap)
          (caddr pt)
        )
      )
      '((+ +) (+ -) (- +) (- -))
    )
    (grdraw pt n col)
  )
)
(defun c:partial_cut ( / ss ent vlaobj pt_brk pt_brk2 tmp_brk new_ent e_last)
  (vl-load-com)
  (princ "\nSelect a curve object.")
  (while
    (not
      (setq ss
        (ssget "_+.:E:S"
          (list
            (cons -4 "<AND")
              (cons 0 "*POLYLINE,LINE,ARC")
              (cons -4 "<NOT")
                (cons -4 "&") (cons 70 112)
              (cons -4 "NOT>")
            (cons -4 "AND>")
          )
        )
      )
    )
  )
  (redraw (setq ent (ssname ss 0)) 3)
  (setq
    vlaobj (vlax-ename->vla-object ent)
  )
  (initget 1)
  (while
    (or
      (equal (setq pt_brk (vlax-curve-getClosestPointToProjection vlaobj (trans (getpoint "\nGive the first point: ") 1 0) '(0.0 0.0 1.0))) (vlax-curve-getStartPoint vlaobj) 1E-13)
      (equal pt_brk (vlax-curve-getEndPoint vlaobj) 1E-13)
    )
    (initget 1)
  )
  (cond
    (pt_brk
      (draw_pt (trans pt_brk 0 1) 3)
      (initget 1)
      (while
        (or
          (equal (setq pt_brk2 (vlax-curve-getClosestPointToProjection vlaobj (trans (getpoint "\nGive the second point: ") 1 0) '(0.0 0.0 1.0))) (vlax-curve-getStartPoint vlaobj) 1E-13)
          (equal pt_brk2 (vlax-curve-getEndPoint vlaobj) 1E-13)
        )
        (initget 1)
      )
      (if pt_brk2
        (progn
          (command "_.undo" "_begin")
          (draw_pt (trans pt_brk2 0 1) 3)
          (if (> (vlax-curve-getParamAtPoint vlaobj pt_brk) (vlax-curve-getParamAtPoint vlaobj pt_brk2))
            (setq tmp_brk pt_brk2 pt_brk2 pt_brk pt_brk tmp_brk)
          )
          (command "_.break" (cons ent (list (trans pt_brk 0 1))) "_first" "_none" (trans pt_brk 0 1) "_none" (trans pt_brk 0 1))
          (setq new_ent (entlast))
          (command "_.break" (cons new_ent (list (trans pt_brk2 0 1))) "_first" "_none" (trans pt_brk2 0 1) "_none" (trans pt_brk2 0 1))
          (setq e_last (entlast))
          (entdel e_last)
          (setq new_ent (entlast))
          (entdel e_last)
          (sssetfirst nil (ssadd new_ent (ssadd)))
          (initget "Yes No")
          (if (eq (getkword "\nErase it? [Yes/No] <No>: ") "Yes")
            (progn (sssetfirst nil nil) (entdel new_ent))
            (sssetfirst nil nil)
          )
          (command "_.undo" "_end")
          (redraw)
        )
      )
    )
  )
  (redraw ent 4)
  (prin1)
)

 

  • Thanks 1
Posted
2 hours ago, Tsuky said:

 

With this?

(defun draw_pt (pt col / rap)
  (setq rap (/ (getvar "viewsize") 50))
  (foreach n
    (mapcar
      '(lambda (x)
        (list
          ((eval (car x)) (car pt) rap)
          ((eval (cadr x)) (cadr pt) rap)
          (caddr pt)
        )
      )
      '((+ +) (+ -) (- +) (- -))
    )
    (grdraw pt n col)
  )
)
(defun c:partial_cut ( / ss ent vlaobj pt_brk pt_brk2 tmp_brk new_ent e_last)
  (vl-load-com)
  (princ "\nSelect a curve object.")
  (while
    (not
      (setq ss
        (ssget "_+.:E:S"
          (list
            (cons -4 "<AND")
              (cons 0 "*POLYLINE,LINE,ARC")
              (cons -4 "<NOT")
                (cons -4 "&") (cons 70 112)
              (cons -4 "NOT>")
            (cons -4 "AND>")
          )
        )
      )
    )
  )
  (redraw (setq ent (ssname ss 0)) 3)
  (setq
    vlaobj (vlax-ename->vla-object ent)
  )
  (initget 1)
  (while
    (or
      (equal (setq pt_brk (vlax-curve-getClosestPointToProjection vlaobj (trans (getpoint "\nGive the first point: ") 1 0) '(0.0 0.0 1.0))) (vlax-curve-getStartPoint vlaobj) 1E-13)
      (equal pt_brk (vlax-curve-getEndPoint vlaobj) 1E-13)
    )
    (initget 1)
  )
  (cond
    (pt_brk
      (draw_pt (trans pt_brk 0 1) 3)
      (initget 1)
      (while
        (or
          (equal (setq pt_brk2 (vlax-curve-getClosestPointToProjection vlaobj (trans (getpoint "\nGive the second point: ") 1 0) '(0.0 0.0 1.0))) (vlax-curve-getStartPoint vlaobj) 1E-13)
          (equal pt_brk2 (vlax-curve-getEndPoint vlaobj) 1E-13)
        )
        (initget 1)
      )
      (if pt_brk2
        (progn
          (command "_.undo" "_begin")
          (draw_pt (trans pt_brk2 0 1) 3)
          (if (> (vlax-curve-getParamAtPoint vlaobj pt_brk) (vlax-curve-getParamAtPoint vlaobj pt_brk2))
            (setq tmp_brk pt_brk2 pt_brk2 pt_brk pt_brk tmp_brk)
          )
          (command "_.break" (cons ent (list (trans pt_brk 0 1))) "_first" "_none" (trans pt_brk 0 1) "_none" (trans pt_brk 0 1))
          (setq new_ent (entlast))
          (command "_.break" (cons new_ent (list (trans pt_brk2 0 1))) "_first" "_none" (trans pt_brk2 0 1) "_none" (trans pt_brk2 0 1))
          (setq e_last (entlast))
          (entdel e_last)
          (setq new_ent (entlast))
          (entdel e_last)
          (sssetfirst nil (ssadd new_ent (ssadd)))
          (initget "Yes No")
          (if (eq (getkword "\nErase it? [Yes/No] <No>: ") "Yes")
            (progn (sssetfirst nil nil) (entdel new_ent))
            (sssetfirst nil nil)
          )
          (command "_.undo" "_end")
          (redraw)
        )
      )
    )
  )
  (redraw ent 4)
  (prin1)
)

 

Thank you Tsuky, top quality as always!

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