Jump to content

Recommended Posts

Posted

I want to Break a line at a certain point - 1 line becomes 2 lines. Then label, with text, the length of the (2) two new lines. I have a labeling routine that works great on a list of lines (ssget). How do I create a list to reprocess with both those new lines in it?

 

Thanks for any help.

Mike in Dallas

Posted

If you use the break command, you will already have one of the two ENAMEs stored, the other you can fetch with (entlast).

 

I asked this same question in your other request, how will the breakpoint be defined? If the user has to pick it, the you can't use a multiple selection with SSGET, but evaluate each line individually.

Posted

I haven't seen the OP's other thread (in fairness I haven't looked either), but since I stumbled upon it now... Perhaps an alternative that would allow for the use of the Break Command _after_ labeling, would involve both (obviously) the selection of the Curve entity, and the break point specification.

 

Not that one couldn't obtain the resultant, additional entity name following the Break Command, and then labeling of course, I just thought I'd throw the idea out there.

 

Cheers

Posted
I haven't seen the OP's other thread (in fairness I haven't looked either), but since I stumbled upon it now... Perhaps an alternative that would allow for the use of the Break Command _after_ labeling, would involve both (obviously) the selection of the Curve entity, and the break point specification.

 

Not that one couldn't obtain the resultant, additional entity name following the Break Command, and then labeling of course, I just thought I'd throw the idea out there.

 

Cheers

 

A viable option, which could save a lot of headaches. From there, you could use vlax-curve-getDistAtPoint and you're set. Nice idea.

Posted

This may work and that would add the broken lines to the variable sad :( at the end of the routine :D

 

(vl-load-com)
(setq sad (ssadd))
(while (and
        (setq ss (entsel "\n Select line :"))
        (eq (cdr (assoc 0 (entget (car ss)))) "LINE")
      )
 (progn
   (command "_.break"
            (car ss)
            "_none"
            (setq p (vlax-curve-getclosestpointto (car ss) (cadr ss)))
            "_none"
            p
   )
   (ssadd (car ss) sad)
   (ssadd (entlast) sad)
 )
)

Posted

You are just picking the closest point to where you select the line. There's no precision.

Try using getpoint and feeding the point to ssget or nentselp.

Posted

It works the same as my previous simple codes , and here is just for examining the code .

 

(setq os (getvar 'osmode))
(setvar 'osmode 512)
(setq sad (ssadd))
(while (setq s (getpoint "\n Select line :"))
 (progn
   (setq ss (ssget s))
   (command "_.break" (ssname ss 0) "_none" (setq p (vlax-curve-getclosestpointto (ssname ss 0) s)) "_none" p)
   (ssadd (ssname ss 0) sad)
   (ssadd (entlast) sad)
 )
)
(setvar 'osmode os)

Posted
(if (and (setq pt (getpoint "\nSpecify point on line: "))
        (setq ss (ssget pt '((0 . "LINE"))))
   )

   ;; BLAH BLAH

)

Posted
It works the same as my previous simple codes

 

No it won't since the point returned by entsel is simply the crosshair position at the time of selection, whereas the entity may be selected using any part of the pickbox aperture - as stated in the documentation:

 

The pick point returned by entsel does not represent a point that lies on the selected object. The point returned is the location of the crosshairs at the time of selection. The relationship between the pick point and the object will vary depending on the size of the pickbox and the current zoom scale.

 

Therefore, as Alan has stated, there is no precision to the picked point, it is a lottery of where the cursor is situated at the moment of selection.

Posted

I see now what was Alan indicating to , that's clear now .

 

Thanks guys :thumbsup:

Posted

Thanks for all the help with this, but most of this is over my head. I'm not at all familiar with VLISP function names. My old school LISP comprehension is not much. I'm just trying to SETQ the last (2) two entities in the dwg database created after the Break command. I'm not sure how ENTNEXT works. Here's my very basic code below written as a test to see if I can capture the last 2 objects...

 

(defun C:TEST (/)

   (setq ent (entsel "\n Select line..."))
   (setq enta (entnext))
     (prompt "\n Select break point...")
     (setq p1 (getpoint))
     (command "break" ent "f" p1 p1 "")

   (setq entb (entnext enta))

   (command "erase" enta "")
   (command "erase" entb "")

)

 

I know it doesn't work. But why not...?

Posted

Once break splits the line into two, you will have one new object, not two. your ent will be the first object and you can get the 2nd object with (entlast).

 

Have a look at this:

 

 

(if (and (setq pnt (getpoint "\nSpecify point at which to break line: "))
        (setq ss (ssget pnt '((0 . "LINE"))))
   )
 (progn (setq ent (ssname ss 0))
        (command "_.break" ent "_F" "_non" pnt "_non" pnt)
        (setq ent2 (entlast))
 )
)

Posted

Hey Alan,

So sorry to keep this going, but..

1. Why did you use the Progn? Was it because of ssname? What if the 0 was set to 1?

2. How would I create a new list with both ENT and ENT2 in it? I have a lengthening routine working and want to run it against this new list of both lines.

3. The only way the Lengthen command works in LISP is if I pass an entity name to it. So I need to give both ENT and ENT2 a name using SETQ.

 

Mike

Posted
Hey Alan,

So sorry to keep this going, but..

1. Why did you use the Progn? Was it because of ssname? What if the 0 was set to 1?

2. How would I create a new list with both ENT and ENT2 in it? I have a lengthening routine working and want to run it against this new list of both lines.

3. The only way the Lengthen command works in LISP is if I pass an entity name to it. So I need to give both ENT and ENT2 a name using SETQ.

 

Mike

 

1. Because, if both parameters are met for IF (valid point with getpoint and ssget selects a line), then I need it to evaluat everything there, not just one thing. PROGN wraps everything together, so I can use it in one IF statement.

2&3. If you want to then feed the two lines to the LENGTHEN command, you have to execute LENGTHEN twice. Once on each variable (ent and ent2).

 

Don't sweat the questions. Every one is here to learn and/or help. :)

Posted

Alan,

Is there a way to set some sort of marker right before the Break command, then capture the next (2) two entities (ENT & ENT2) added to the dwg database?

 

Mike

 

 

Once break splits the line into two, you will have one new object, not two. your ent will be the first object and you can get the 2nd object with (entlast).

 

Have a look at this:

 

 

(if (and (setq pnt (getpoint "\nSpecify point at which to break line: "))
        (setq ss (ssget pnt '((0 . "LINE"))))
   )
 (progn (setq ent (ssname ss 0))
        (command "_.break" ent "_F" "_non" pnt "_non" pnt)
        (setq ent2 (entlast))
 )
)

Posted
Alan,

Is there a way to set some sort of marker right before the Break command, then capture the next (2) two entities (ENT & ENT2) added to the dwg database?

 

Mike

 

You don't have to do that. When an object is split with the break command, one of the two entities is the same (just shorter) and the other is the newest created object in the drawing (entlast). There's no need to go any farther. My above code will break and line and give you both pieces (ent and ent2).

Posted

Good afternoon Alan,

Here's my best try. I think I have something out of order. What do you think?

 

(defun C:test (/ pt1 pt2 pt3 pt4 ent ent1)

(setvar "CMDECHO" 1)
(setvar "OSMODE" 4)

   (setq ent (entsel "\n Select beam to splice..."))

;----------------------------------------------------------------
;
; thanks to Alanjt for the below code portion
;
;----------------------------------------------------------------

         (if (and (setq pt1 (getpoint "\n Specify splice point: "))
              (setq ents (ssget pt1 '((0 . "LINE"))))
         ); end and

       (progn 
          (setq ent (ssname ents 0))
          (command "_.break" ent "_F" "_non" pt1 "_non" pt1)
          (setq ent1 (entlast))

       ); end progn

         ); end if

;----------------------------------------------------------------------------------

       (progn
          (setq pt3 (cdr (assoc 10 (entget ent1))))
          (setq pt4 (cdr (assoc 11 (entget ent1))))
          (setq mpt (midpt pt3 pt4))

          (command "lengthen" "De" "24.0" ent "")
          (command "lengthen" "De" "24.0" ent1 "")
          (command "mirror" ent1 "" mpt "@ 0,10000" "y");flips the element in the correct direction...lazy way, but it works
       ); end progn


(setvar "OSMODE" 1)

);end defun

;----------------------------------------------------------------
;- code portion below from...
;- Copyright 2008 Jeff Winship. All rights Reserved.
;-
;----------------------------------------------------------------

(defun midpt (pt3 pt4 / Xavg Yavg Zavg)

   ;-Calculate the X, Y and Z averages
   (setq Xavg (/ (+ (car pt3) (car pt4)) 2.0))
   (setq Yavg (/ (+ (cadr pt3) (cadr pt4)) 2.0))
   (setq Zavg (/ (+ (caddr pt3) (caddr pt4)) 2.0))

   ;-Return the midpoint as a list
   (list Xavg Yavg Zavg)

)

Posted

Well done! Take the entsel line out. You don't need it. Ssget selects the line using an xy from getpoint for your selection.

 

I wrote this one e before I left the office but wanted you to try for yourself. The number might not be right but you can change it. I'll be back on Monday. I'm actually posting from my phone while on the road.

 

(defun c:test (/ AT:DrawX AT:CycleThroughSS p1 ent line ang len len1 len2 copy)

 (vl-load-com)

 (defun AT:DrawX (P C)
   ;; Draw and "X" vector at specified point
   ;; P - Placement point for "X"
   ;; C - Color of "X" (must be integer b/w 1 & 255)
   ;; Alan J. Thompson, 10.31.09
   (if (vl-consp P)
     ((lambda (d)
        (grvecs (cons C
                      (mapcar (function (lambda (n) (polar P (* n pi) d)))
                              '(0.25 1.25 0.75 1.75)
                      )
                )
        )
        P
      )
       (* (getvar 'viewsize) 0.02)
     )
   )
 )

 (defun AT:CycleThroughSS (ss / l i e)
   ;; Cycle through a selection set to choose one
   ;; ss - selection set
   ;; Alan J. Thompson, 03.30.11
   (if (eq (type ss) 'PICKSET)
     (if (eq (setq l (sslength ss)) 1)
       (ssname ss 0)
       (progn (princ "\n<Tab> to cycle through entities: ")
              (redraw (setq e (ssname ss (setq i 0))) 3)
              (while (eq (cadr (grread nil 10)) 9)
                (mapcar 'redraw (list e (setq e (ssname ss (setq i (rem (1+ i) l))))) '(4 3))
              )
              (redraw e 4)
              e
       )
     )
   )
 )

 (redraw)

 (if (and (AT:DrawX (setq p1 (getpoint "\nSpecify first point on curve: ")) 3)
          (or (setq ent (AT:CycleThroughSS
                          (ssget "_C"
                                 (list (car p1) (cadr p1))
                                 (list (car p1) (cadr p1))
                                 '((0 . "LINE"))
                          )
                        )
              )
              (progn (alert "Point must be on line!") (redraw))
          )
     )
   (progn
     (redraw ent 3)

     (setq line (vlax-ename->vla-object ent)
           ang  (vla-get-angle line)
           len  (vla-get-length line)
           len1 (- len (vlax-curve-getDistAtPoint ent p1))
           len2 (- len len1)
           copy (vla-copy line)
     )

     (vlax-put line 'EndPoint (polar (vlax-get line 'StartPoint) ang (+ len2 24.)))
     (vlax-put copy 'StartPoint (polar (vlax-get copy 'EndPoint) (+ ang pi) (+ len1 24.)))
   )
 )
 (princ)
)

Posted

Good day Alan,

I've since finished my "lengthening" code, but am stuck on another routine.

It runs fine, but near the end, I get this...

 

Starting point of rafter layout:

Angle rafters to run:Unknown command "CLNGIT". Press F1 for help.

Unknown command "CLNGIT". Press F1 for help.

Unknown command "CLNGIT". Press F1 for help.

nil

 

I can't figure out where the returns are coming from.

Here's the complete code. Try not to cry. I know it's not nearly as sophisticated as your coding abilities

 

 

(defun C:ClngIt ()

;;...................................................................
;;
;;        << Copyright 2013 CES Global >>
;;          Written by Spike for CES Global 2013
;;...................................................................

(setvar "CMDECHO" 0)
(setvar "expert" 5)
(setq mspacing "24")
(setq Btype "B")
(setq 2xtxt "10")
(setq clay (getvar "CLAYER"))

;--------------------degress to radians--------------------------------------------

(defun dtr (a)
 (/ (* a 180.0) pi)
)

;----------------------------- ECHOGETS -------------------------------------

(defun Echoget2 (DEFAULT MSG / TEMP2)
   (setq TEMP2 (getstring T (strcat MSG "<" DEFAULT ">: ")))
    (IF (/= "" TEMP2) TEMP2 DEFAULT)
)

;

(defun Echoget3 (DEFAULT MSG / TEMP3)
   (setq TEMP3 (getstring T (strcat MSG "<" DEFAULT ">: ")))
    (IF (/= "" TEMP3) TEMP3 DEFAULT)
)
;
;
/
(defun Echoget4 (DEFAULT MSG / TEMP4)
   (setq TEMP4 (getstring T (strcat MSG "<" DEFAULT ">: ")))
    (IF (/= "" TEMP4) TEMP4 DEFAULT)
)

;----------------------------------Main program body--------------------------------------------------

;.................capture user choice for 2x type.............................................................

(prompt "\nCeiling framing tool: ")
(terpri)
   (setq choice2 (strcase (Echoget2 2xtxt "What type of framing...2x(4), 2x(6), 2x(, 2x(10), 2x(12)?")))
       (cond 
           ((= choice2 "4")
               (setq 2xtxt " (2x4)"))

           ((= choice2 "6")
               (setq 2xtxt " "))

           ((= choice2 "8")
               (setq 2xtxt " (2x8)"))

           ((= choice2 "10")
               (setq 2xtxt " (2x10)"))

           ((= choice2 "12")
               (setq 2xtxt "(2x12)"))
       ); end cond

;..................capture user choice for member spacing................................

   (setq choice3 (strcase (echoget3 mspacing "Member spacing 12, 16, 18, 24...?")))
       (cond 
           ((= choice3 "12")
           (setvar "HPNAME" "RFSP_12"))

           ((= choice3 "16")
           (setvar "HPNAME" "RFSP_16"))

           ((= choice3 "18")
           (setvar "HPNAME" "RFSP_18"))

           ((= choice3 "24")
           (setvar "HPNAME" "RFSP_24"))

       );end cond    

;.................capture user choice for hatch creation mode.............................................................

   (setvar "OSMODE" 3)
   (setq choice4 (strcase (echoget4 Btype "Create hatch by inside point or multiple points...(B)oundary or (P)oints?")))
   (progn
       (cond 
           ((= choice4 "B")
               (setq spt (getpoint "\nStarting point of rafter layout:"))
               (command "HPORIGIN" spt)
               (setvar "OSMODE" 0)
               (setvar "autosnap" 47)
               (prompt "\nAngle rafters to run:")
               (setq tang (getangle spt))
               (setq rang (dtr tang))
                   (while (= 1 (getvar "cmdactive"))
                      (setq bppt (getpoint))
                   );end while
               (command "bpoly" bppt "")
               (setq bdry (entlast))
           );end choice4

           ((= choice4 "P")
           (setq spt (getpoint "\nStarting point of rafter layout:"))    
               (command "HPORIGIN" spt)
               (setvar "autosnap" 47)
               (prompt "\nAngle rafters to run:")
               (setq tang (getangle spt))
               (setq rang (dtr tang))
               (princ "\nPick points of roof area...")
               (command "pline")
                   (while (= 1 (getvar "cmdactive"))
                   (command PAUSE )
                   );end while
               (setq bdry (entlast))
           );end choice4

       );end cond

   (progn
       (if (= (TBLSEARCH "LAYER" "_HOLD") nil)
       (command "layer" "make" "_HOLD" "c" "202" "" "" )
       );end if
   )

   (command "layer" "s" "_HOLD" "")
   (command "hatch" (getvar "HPNAME") "1.0" rang bdry "")
   (command "explode" "l" "")
   (command "change" "P" "" "P" "LA" tlay "")

(C:lblc)

   (setq holds (ssget "X" '((8 . "_HOLD"))))
   (command "erase" holds "")

   );end progn

;--------------------------------------------------------------------------

   (setvar "LUNITS" 3)
   (setvar "LUPREC" 4)
   (setvar "OSMODE" 1)
   (setvar "autosnap" 63)
   (setq 2xtxt choice2)
   (setq mspacing choice3)
   (setq btype choice4)
   (command "layer" "s" clay "")

);end defun

Let me know what you think.

Again, thanks for all your expertise.

Mike in BigD

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