Jump to content

Finding a point in an Entity problem


Rob-GB

Recommended Posts

I am working on a lisp routine and got it to draw the first part but now need to select a point on that part for it to repeat from.

I have been looking into the Entget, Entsel commands but getting confused with the results.:oops:

Is there a quick way to select the point I need? or more correctly ask the lisp to find it and set it as next start point.

 

Any pokes in the right direction gratefully received.

Ta,

Rob.

Link to comment
Share on other sites

If you could post some of your codes that would be much clearer for all to help you with it without guessing which is the right one you want .

 

Anyway here is one you may find it useful or so .:)

 

(entmakex (list (cons 0 "LINE")(cons 10 '(0. 0. 0.))(cons 11 '(1. 0. 0.)))) ; Draw a Line 
(setq e (entlast)); get the last Entity 
(setq pt (cdr (assoc 10 (entget e)))) ; get the start point of the last entity which is "e"

Tharwat

Link to comment
Share on other sites

Thanks Tharwat, all the examples I have read are based on single lines.

So to clarify I will put original code up and the lisp that works, the continuation of the lisp is in a separate file and way to messed up to see light of day:oops:

The point I need is top right corner of drawn tread for the next IP (insert point), it is finding the end point of the top line within the return from the entlast/entget that is my problem. I think!

;=========================================================================================;
(defun C:stair1 (/ IP GOING RISE NOSING TRTH RITH STRTH WIDE A B C D E F G H K S N P Q R    
     R1 R2 R3 R4 R5 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10
      OLDSNAP OLDBLIP OLDLIGHT OLDLAY)
;=========================================================================================;
; lisp routine to draw basic staircase
; by Rob-GB 27.01.2011
(setq OLDSNAP (getvar "OSMODE")
)
 (setq OLDBLIP (getvar "BLIPMODE")  ;store settings
)
 (setq OLDLIGHT (getvar "HIGHLIGHT")
)
 (setq OLDLAY (getvar "CLAYER")
)
 (setvar "CMDECHO" 0)
  (setvar "BLIPMODE" 0)
;=========================================================================================;
;Basic dims required
;=========================================================================================;
(or GOING (setq GOING 230.0))
 (or RISE  (setq RISE  200.0))
  (or TRTH    (setq TRTH      25.0))
   (or RITH    (setq RITH      9.0))
    (or WIDE    (setq WIDE     900.0))
     (or STRTH (setq STRTH 33.0))
             (or NOSING (setq NOSING 25.0))
       (setq A (rtos GOING 2 1))
 (setq B (rtos RISE  2 1))
  (setq C (rtos TRTH  2 1))
          (setq D (rtos RITH  2 1))
    (setq E (rtos WIDE  2 1))
     (setq F (rtos STRTH 2 1))
             (setq G (rtos NOSING 2 1))

(setq GOING (cond ((getdist (strcat "\nEnter going of tread <"A">:")))     (T (setq GOING GOING))))
(setq RISE  (cond ((getdist (strcat "\nEnter rise of step <"B">:")))       (T (setq RISE RISE))))
(setq TRTH  (cond ((getdist (strcat "\nEnter tread thickness <"C">:")))    (T (setq TRTH TRTH))))
(setq RITH  (cond ((getdist (strcat "\nEnter riser thickness <"D">:")))    (T (setq RITH RITH))))
(setq WIDE  (cond ((getdist (strcat "\nEnter width across strings <"E">:")))      (T (setq WIDE WIDE))))  
(setq STRTH (cond ((getdist (strcat"\nEnter string thickness <"F">:")))    (T (setq STRTH STRTH))))
(setq NOSING (cond ((getdist (strcat"\nEnter nosing projection <"G">:")))   (T (setq NOSING NOSING))))

(setq IP (getpoint "\nInsertion Point: ")
)  ; bottom left finish floor level of first riser, stair will be drawn rising from left to right

;============================================================================================================;
;set other dims
(setq GR 10)
 (SETQ GRD (- TRTH GR))

;============================================================================================================;
;;; Layer Function - Set Layer & Linetype.                          ;Function Description
(defun SLL (NLAY CLR LT / LAY FRZ)                                  ;Define function, Declare local variables and arguments
 (setq LAY  (tblsearch "layer" NLAY))                              ;Search drawing to find layer, Note: (NOT USED)
  (if                                                              ;If the following returns true
   (not LAY)                                                       ;Layer not in drawing
    (command "_.layer" "m" NLAY "c" CLR "" "lt" LT "" "")          ;Layer command ~ make new layer with color and linetype
     (progn                                                        ;Then do the following
      (setq FRZ (cdr (assoc 70 LAY)))                              ;Variable FRZ is frozen layer
       (if (= FRZ 65)                                              ;Layer frozen from last edit
        (progn                                                     ;Then do the following
         (command "_.layer" "t" NLAY "")                           ;Thaw new layer if frozen
          (command "_.layer" "s" NLAY ""))                         ;Set new layer
           (command "_.layer" "s" NLAY ""))))                      ;Set new layer
)                                                                   ;End define function  
;=========================================================================================;
; plot points for side elevation
(defun DTR (a) (* PI (/ a 180.0))  ;degrees to radians
)  

(setq R1 (POLAR IP (DTR 90.0) (- RISE GRD)) ; riser side elevation from insert point
)
(setq R2 (POLAR R1 (DTR 0.0) RITH)
)
(setq R3 (POLAR R2 (DTR 270.0) (- RISE GRD))
)
(setq R4 (POLAR R3 (DTR 270.0) TRTH)
)
(setq R5 (POLAR R4 (DTR 180.0) RITH)
)
;====================================================================================;
 ;treads
(setq T1 (POLAR R1 (DTR 270.0) GR)  ; top corner head
)
(setq T2 (POLAR T1 (DTR 180.0) NOSING)
)
(setq T4 (POLAR T2 (DTR 90.0) TRTH)
)
(setq T5 (POLAR IP (DTR 90.0) RISE) 
)  
(setq T6 (POLAR T5 (DTR 0.0) GOING)
)
(setq T7 (POLAR T6 (DTR 270.0) TRTH)
)
(setq T8 (POLAR T7 (DTR 180.0) (- GOING RITH))
)
(setq T9 (POLAR T2 (DTR 0.0) (/ TRTH 2))
)
(setq T10 (POLAR T4 (DTR 0.0) (/ TRTH 2))
)
(setq T3 (POLAR T9 (DTR 90.0) (/ TRTH 2)) ;centre point for tread nosing
) 
;=========================================================================================;
(SLL "Riser" "72" "CONTINUOUS")   
(command "_.PLINE" IP R1 R2 R3 R4 R5 IP ""
); riser drawn

;=========================================================================================;
;plot frame elevation
(setvar "OSMODE" 0)
(SLL "Tread" "63" "CONTINUOUS")                              ;Go to SLL Layer Function, Set Layer, Color & Linetype
(command "_.PLINE" T10 T5 T6 T7 T8 R2 R1 T1 T9 ""
  )
(command "arc" "c" T3 T10 T9 
)    ;nosing
;=========================================================================================;
;=========================================================================================;
;=========================================================================================;
(setvar "CLAYER" OLDLAY)
(setvar "OSMODE" OLDSNAP)
(setvar "BLIPMODE" OLDBLIP)
(setvar "HIGHLIGHT" OLDLIGHT)
(princ)
);defun

 

Cheers, Rob.

Stair1.LSP

Link to comment
Share on other sites

Note: your variable name (ip) is not recommend to be used as variable because it already used by Autocad ( ip = 3.1415962) which

is the angular 180. degrees . So please change it to another name to avoid any fails of the routine or maybe with Autocad itself.

 

I guess you can repeat all your routine by setting this .

 

The Point that you looking for is T6.

(setq t6 ip )

 

Take a look at the following example for continuation of Line command .

 

(if (setq[color=blue] pt1[/color] (getpoint "\n Specify start point :"))
   (while
     (setq [color=blue]pt2[/color] (getpoint pt1 "\n Next point:"))
      (entmakex (list (cons 0 "LINE")(cons 10 pt1)(cons 11 pt2)))
      [color=red][b](setq pt1 pt2)[/b][/color]
     )
   (princ "\n Program Cancelled")
   )

Hope this help you out with it. :)

 

Tharwat

Link to comment
Share on other sites

ip is not defined, it's pi.

 

Oooooops :shock: That's right .

 

I am little bit in a hurry due to time in the office is almost over . :?

 

Thanks Alanjt

Link to comment
Share on other sites

Oooooops :shock: That's right .

 

I am little bit in a hurry due to time in the office is almost over . :?

 

Thanks Alanjt

So, because you are in a hurry, you feel it necessary to answer this guy incorrectly, just so you can answer before going home.

Link to comment
Share on other sites

Here it goes ,the same I said before it is the T6 .

 

To repeat the form 5 times and you can adjust it as you would like to .

 

I am sorry for modifying your codes , but I did that to understand whats going on .

 

(defun C:stair1 (/ IP GOING RISE NOSING TRTH RITH STRTH WIDE A B C D E F G H K S N P Q R    
     R1 R2 R3 R4 R5 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10  OLDSNAP OLDBLIP OLDLIGHT OLDLAY)
 
(setq OLDSNAP (getvar "OSMODE"))
 (setq OLDBLIP (getvar "BLIPMODE"))
 (setq OLDLIGHT (getvar "HIGHLIGHT"))
 (setq OLDLAY (getvar "CLAYER"))
 (setvar "CMDECHO" 0)
  (setvar "BLIPMODE" 0)
(or GOING (setq GOING 230.0))
 (or RISE  (setq RISE  200.0))
  (or TRTH    (setq TRTH      25.0))
   (or RITH    (setq RITH      9.0))
    (or WIDE    (setq WIDE     900.0))
     (or STRTH (setq STRTH 33.0))
      (or NOSING (setq NOSING 25.0))
       (setq A (rtos GOING 2 1))
 (setq B (rtos RISE  2 1))
  (setq C (rtos TRTH  2 1))
          (setq D (rtos RITH  2 1))
    (setq E (rtos WIDE  2 1))
     (setq F (rtos STRTH 2 1))
             (setq G (rtos NOSING 2 1))
(setq GOING (cond ((getdist (strcat "\nEnter going of tread <"A">:")))     (T (setq GOING GOING))))
(setq RISE  (cond ((getdist (strcat "\nEnter rise of step <"B">:")))       (T (setq RISE RISE))))
(setq TRTH  (cond ((getdist (strcat "\nEnter tread thickness <"C">:")))    (T (setq TRTH TRTH))))
(setq RITH  (cond ((getdist (strcat "\nEnter riser thickness <"D">:")))    (T (setq RITH RITH))))
(setq WIDE  (cond ((getdist (strcat "\nEnter width across strings <"E">:")))      (T (setq WIDE WIDE))))  
(setq STRTH (cond ((getdist (strcat"\nEnter string thickness <"F">:")))    (T (setq STRTH STRTH))))
(setq NOSING (cond ((getdist (strcat"\nEnter nosing projection <"G">:")))   (T (setq NOSING NOSING))))
(setq IP (getpoint "\nInsertion Point: "))  
 [color=red][b](repeat 5[/b][/color]
(setq GR 10)
 (SETQ GRD (- TRTH GR))
   (defun SLL (NLAY CLR LT / LAY FRZ)                                  ;Define function, Declare local variables and arguments
 (setq LAY  (tblsearch "layer" NLAY))                              ;Search drawing to find layer, Note: (NOT USED)
  (if                                                              ;If the following returns true
   (not LAY)                                                       ;Layer not in drawing
    (command "_.layer" "m" NLAY "c" CLR "" "lt" LT "" "")          ;Layer command ~ make new layer with color and linetype
     (progn                                                        ;Then do the following
      (setq FRZ (cdr (assoc 70 LAY)))                              ;Variable FRZ is frozen layer
       (if (= FRZ 65)                                              ;Layer frozen from last edit
        (progn                                                     ;Then do the following
         (command "_.layer" "t" NLAY "")                           ;Thaw new layer if frozen
          (command "_.layer" "s" NLAY ""))                         ;Set new layer
           (command "_.layer" "s" NLAY ""))))                      ;Set new layer
)   
(setq R1 (POLAR IP (DTR 90.0) (- RISE GRD)) )
(setq R2 (POLAR R1 (DTR 0.0) RITH))
(setq R3 (POLAR R2 (DTR 270.0) (- RISE GRD)))
(setq R4 (POLAR R3 (DTR 270.0) TRTH))
(setq R5 (POLAR R4 (DTR 180.0) RITH))
(setq T1 (POLAR R1 (DTR 270.0) GR))
(setq T2 (POLAR T1 (DTR 180.0) NOSING))
(setq T4 (POLAR T2 (DTR 90.0) TRTH))
(setq T5 (POLAR IP (DTR 90.0) RISE) )  
(setq T6 (POLAR T5 (DTR 0.0) GOING))
(setq T7 (POLAR T6 (DTR 270.0) TRTH))
(setq T8 (POLAR T7 (DTR 180.0) (- GOING RITH)))
(setq T9 (POLAR T2 (DTR 0.0) (/ TRTH 2)))
(setq T10 (POLAR T4 (DTR 0.0) (/ TRTH 2)))
(setq T3 (POLAR T9 (DTR 90.0) (/ TRTH 2))) 
(SLL "Riser" "72" "CONTINUOUS")   
(command "_.PLINE" IP R1 R2 R3 R4 R5 IP "")
(setvar "OSMODE" 0)
(SLL "Tread" "63" "CONTINUOUS")                            
(command "_.PLINE" T10 T5 T6 T7 T8 R2 R1 T1 T9 "" )
(command "arc" "c" T3 T10 T9 )    ;nosing
[color=red][b](setq IP t6)[/b][/color])
(setvar "CLAYER" OLDLAY)
(setvar "OSMODE" OLDSNAP)
(setvar "BLIPMODE" OLDBLIP)
(setvar "HIGHLIGHT" OLDLIGHT)
(princ)
   )
(defun DTR (a) (* PI (/ a 180.0))  
)  

 

Best regards.

 

Tharwat

Link to comment
Share on other sites

Thanks for the advice and the example code, much appreciated:)

Off to have another try at my code, think I may have been trying to set (setq t6 ip ) as (setq ip t6) when it drew itself 5986 times in the same place, told you my v2 code was messy:oops:

Rob.

 

edit:- Tharwat; No problems with you altering my code, it will help me and probably others too, thank you.

 

alanjt:- Thanks for the clarification over the 'IP' bit, wasn't sure about that myself but we all make hiccoughs at times (except Remark...but he was programmed that way!! :lol:)

Edited by Rob-GB
Slow typing = missing info
Link to comment
Share on other sites

So, because you are in a hurry, you feel it necessary to answer this guy incorrectly, just so you can answer before going home.

 

It is correctly Alan ,:)

 

Check that out.

Link to comment
Share on other sites

Prior to my entlist deviation that got me confused I had tried the 'repeat' option then the 'while' option but could not even get that right! So thanks to Tharwat's bit of code I saw things more clearly.:) So...

Here is the revised code and the .lsp file for those who would like to use it on an 'as seen' basis, it works on Acad2010. If you do use it and alter it to improve it's functionality please post here for others to learn from. (As will I when I alter it as planned)

Cheers, Rob.

 

=========================================================================================;
(defun C:stair1a (/ IP GOING RISE NOSING TRTH RITH TIMES GR GRD A B C D G     
     R1 R2 R3 R4 R5 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10
      OLDSNAP OLDBLIP OLDLIGHT OLDLAY)
;=========================================================================================;
; lisp routine to draw basic timber staircase side elevation 
; by Rob-GB 27.01.2011
; Thanks to, in no special order, Buzzard, Lee Mac, Kenny at AfraLISP, Tharwat, alanjt and the many others
; at Cadtutor for any and all assistance given to those of us on the learning curve
(setq OLDSNAP (getvar "OSMODE")
)
 (setq OLDBLIP (getvar "BLIPMODE")  ;store settings
)
 (setq OLDLIGHT (getvar "HIGHLIGHT")
)
 (setq OLDLAY (getvar "CLAYER")
)
 (setvar "CMDECHO" 0)
  (setvar "BLIPMODE" 0)
;=========================================================================================;
;Basic dims required
;=========================================================================================;
(or GOING (setq GOING 230.0))
 (or RISE  (setq RISE  200.0))
  (or TRTH    (setq TRTH      25.0))
   (or RITH    (setq RITH      9.0))
    (or WIDE    (setq WIDE     900.0))
     (or NOSING (setq NOSING 25.0))
      (setq A (rtos GOING 2 1))
       (setq B (rtos RISE  2 1))
 (setq C (rtos TRTH  2 1))
         (setq D (rtos RITH  2 1))
   (setq G (rtos NOSING 2 1))

(setq GOING (cond ((getdist (strcat "\nEnter going of tread <"A">:")))     (T (setq GOING GOING))))
(setq RISE  (cond ((getdist (strcat "\nEnter rise of step <"B">:")))       (T (setq RISE RISE))))
(setq TRTH  (cond ((getdist (strcat "\nEnter tread thickness <"C">:")))    (T (setq TRTH TRTH))))
(setq RITH  (cond ((getdist (strcat "\nEnter riser thickness <"D">:")))    (T (setq RITH RITH))))
(setq NOSING (cond ((getdist (strcat"\nEnter nosing projection <"G">:")))   (T (setq NOSING NOSING))))
(setq TIMES (getint "\nEnter number of risers : ")) 
(setq IP (getpoint "\nInsertion Point: ")
)  ; bottom left finish floor level of first riser, stair will be drawn rising from left to right
(repeat TIMES
;============================================================================================================;
;set other dims
(setq GR 10)   ;sets depth of groove in tread to accept riser
 (SETQ GRD (- TRTH GR)) ;gives tread thickness less riser groove depth

;============================================================================================================;
;;; Layer Function - Set Layer & Linetype.                          ;Function Description
(defun SLL (NLAY CLR LT / LAY FRZ)                                  ;Define function, Declare local variables and arguments
 (setq LAY  (tblsearch "layer" NLAY))                              ;Search drawing to find layer, Note: (NOT USED)
  (if                                                              ;If the following returns true
   (not LAY)                                                       ;Layer not in drawing
    (command "_.layer" "m" NLAY "c" CLR "" "lt" LT "" "")          ;Layer command ~ make new layer with color and linetype
     (progn                                                        ;Then do the following
      (setq FRZ (cdr (assoc 70 LAY)))                              ;Variable FRZ is frozen layer
       (if (= FRZ 65)                                              ;Layer frozen from last edit
        (progn                                                     ;Then do the following
         (command "_.layer" "t" NLAY "")                           ;Thaw new layer if frozen
          (command "_.layer" "s" NLAY ""))                         ;Set new layer
           (command "_.layer" "s" NLAY ""))))                      ;Set new layer
)                                                                   ;End define function  
;=========================================================================================;
; plot points for side elevation
(defun DTR (a) (* PI (/ a 180.0))  ;degrees to radians
)  

(setq R1 (POLAR IP (DTR 90.0) (- RISE GRD)) ; riser side elevation from insert point
)
(setq R2 (POLAR R1 (DTR 0.0) RITH)
)
(setq R3 (POLAR R2 (DTR 270.0) (- RISE GRD))
)
(setq R4 (POLAR R3 (DTR 270.0) TRTH)
)
(setq R5 (POLAR R4 (DTR 180.0) RITH)
)
;====================================================================================;
 ;treads
(setq T1 (POLAR R1 (DTR 270.0) GR)  ; top corner head
)
(setq T2 (POLAR T1 (DTR 180.0) NOSING)
)
(setq T4 (POLAR T2 (DTR 90.0) TRTH)
)
(setq T5 (POLAR IP (DTR 90.0) RISE) 
)  
(setq T6 (POLAR T5 (DTR 0.0) GOING)
)
(setq T7 (POLAR T6 (DTR 270.0) TRTH)
)
(setq T8 (POLAR T7 (DTR 180.0) (- GOING RITH))
)
(setq T9 (POLAR T2 (DTR 0.0) (/ TRTH 2))
)
(setq T10 (POLAR T4 (DTR 0.0) (/ TRTH 2))
)
(setq T3 (POLAR T9 (DTR 90.0) (/ TRTH 2)) ;centre point for tread nosing
) 
;=========================================================================================;
(SLL "Riser" "72" "CONTINUOUS")   
(command "_.PLINE" IP R1 R2 R3 R4 R5 IP ""
); riser drawn

;=========================================================================================;
;plot frame elevation
(setvar "OSMODE" 0)
(SLL "Tread" "63" "CONTINUOUS")                              ;Go to SLL Layer Function, Set Layer, Color & Linetype
(command "_.PLINE" T10 T5 T6 T7 T8 R2 R1 T1 T9 ""
  )
(command "arc" "c" T3 T10 T9 
)    ;nosing
(setq IP T6))
;=========================================================================================;
;=========================================================================================;
;=========================================================================================;
(setvar "CLAYER" OLDLAY)
(setvar "OSMODE" OLDSNAP)
(setvar "BLIPMODE" OLDBLIP)
(setvar "HIGHLIGHT" OLDLIGHT)
(princ)
);defun

 

Stair1a.LSP

Link to comment
Share on other sites

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