Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ssget for measure command

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
bkp
Contributor
761 Views, 9 Replies

ssget for measure command

Hi all,

I am trying to make a truss via autolisp.

 

(vmon)
(defun c:tus()

(alert "Please turn CAPS on")
(setq c1 (getpoint "Pick Bottom Left Point: "))
(setq l1 (getreal "Enter Length of Truss: "))
(setq h1 (getreal "Enter Height of Truss at the Centre: "))
(setq h2 (getreal "Enter Height of Truss at Support: "))
(setq p1 (getreal "Enter Purlin Distance: "))
(setq osm (getvar "osmode"))
(setvar "osmode" 0)
(setq c2 (list (+ (car c1) l1) (cadr c1)))
(setq c3 (list (car c1) (+ (cadr c1) h2)))
(setq c4 (list (car c2) (+ (cadr c2) h2)))
(setq c5 (list (+ (car c1) (/ l1 2)) (+ (cadr c1) h1)))
(setq c6 (list (- (car c1) 200) (cadr c1)))
(setq c7 (list (car c1) (- (cadr c1) 200)))
(setq c8 (list (+ (car c1) (/ l1 2)) (cadr c1)))

(command "layer" "s" "dim" "")
(command "dim1" "ver" c1 c3 c6 "")
(command "dim1" "hor" c1 c2 c7 "")

(command "layer" "s" "center2" "")
(command "line" c1 c3 "")
(command "copy" "l" "" c1 c2 "")
(command "line" c1 c2 "")
(command "line" c8 c5 "")
(command "line" c3 c5 "")
(command "mirror" "l" "" c5 c8 "")
(command "measure" "l" p1)

 

In that, I want to make a selection set of points made by measure command.

 

Which method will be applicable in this case.

I have to give reference inbetween two points.

something like : (ssget '((0 . "POINT") (-4 . "<,>=,=") (10 c1))) and (ssget '((0 . "POINT") (-4 . "<,>=,=") (10 c2))).

 

But its not working.

 

Please help me on this. May be I am not using the points correctly

 

 

 

 

 

9 REPLIES 9
Message 2 of 10
stevor
in reply to: bkp

Rather than using SSGET you can use ENTLAST to set a reference entitiy name and again in a WHILE loop to collect the POINTs. Examples are here and on the web.
S
Message 3 of 10
bkp
Contributor
in reply to: stevor

Thanks for the reply Stevor.

 

Can you please provide a ready reference.

 

I am searching this site since last many days now, couldnt locate any post of this kind. 

 

My logic is to copy the centre line i.e. line from c8 to c5 and then copy it to those points ( made via selection set). And then i can trim those lines using the Line made of c1 to c2. But making a selection set of points which I am creating through the measure command is not known to me.

 

And the number of points can vary everytime depending on length of the truss.

 

So... reference will be of great help.

Message 4 of 10
bkp
Contributor
in reply to: bkp

And yes, one more thing, I dont want to create a selection set via window or crossing. If the user is not having that window in the screen, it might not draw the truss properly. Of course, this is my assumption by the readings I had uptil now. 

 

Please correct me if I am going in a wrong direction

Message 5 of 10
Olivier.R
in reply to: bkp

Hi bkp,

I am french and it was not easy for to explain you other solution but that three lines can do your selection set.

 

(setq cmin (list (min (car c1) (car c2)) (min (cadr c1) (cadr c2)) (min (caddr c1) (caddr c2))))
(setq cmax (list (max (car c1) (car c2)) (max (cadr c1) (cadr c2)) (max (caddr c1) (caddr c2))))
(setq ss (ssget "_X" (list '(0 . "point") '(-4 . "<and") '(-4 . ">=,>=,>=") (cons 10 c1) '(-4 . "<=,<=,<=") (cons 10 c2) '(-4 . "and>"))))

 

Sorry for bad english.

 

Olivier

Message 6 of 10
Kent1Cooper
in reply to: bkp


@Bkp wrote:

.... I want to make a selection set of points made by measure command.

....


An example of stevor's suggested approach is hmsilva's message here.  Modifying that, try something like this:

....

(command "mirror" "l" "" c5 c8 "")

(setq

  ss (ssadd); start with empty selection set
  ent (entlast); reference start-point

); setq
(command "measure" "l" p1)

(while (setq ent (entnext ent)); stepping through entities newer than the Mirrored one

  (ssadd ent ss)

); while

 

That should leave all the Point entities in the 'ss' selection-set variable, to do with what you like.

Kent Cooper, AIA
Message 7 of 10
bkp
Contributor
in reply to: Kent1Cooper

Sorry for the late reply. It was a long weekend back here.

 

Thank you very much Mr. Oliver and Mr. Cooper.

 

I will to try to finish the lisp file by today. In case, I am making any mistakes again, I will come back.

 

Thanks once again.

Message 8 of 10
Kent1Cooper
in reply to: Olivier.R


@Olivier.R wrote:

.... 

(setq cmin (list (min (car c1) (car c2)) (min (cadr c1) (cadr c2)) (min (caddr c1) (caddr c2))))
(setq cmax (list (max (car c1) (car c2)) (max (cadr c1) (cadr c2)) (max (caddr c1) (caddr c2))))
(setq ss (ssget "_X" (list '(0 . "point") '(-4 . "<and") '(-4 . ">=,>=,>=") (cons 10 c1) '(-4 . "<=,<=,<=") (cons 10 c2) '(-4 . "and>"))))

....


There is a more concise way to find the cmin and cmax variables, if you're interested.

 

The code finds the Points within a window with c1 at lower left and c2 at upper right.  It's using c1 and c2 for the reference locations to test Point entity locations against, where I believe the intent is to use cmin and cmax [which are otherwise never used]:

 

(setq

  cmin (mapcar 'min c1 c2)

  cmax (mapcar 'max c1 c2)

  ss

    (ssget "_X"
    (list
      '(0 . "point")
      '(-4 . "<and")
        '(-4 . ">=,>=,>=") (cons 10 cmin)
        '(-4 . "<=,<=,<=") (cons 10 cmax)
      '(-4 . "and>")
    )
  )

)

 

In this particular routine, because of the way it's written, c1 and c2 have a consistent relationship, which means it's not necessary to determine cmin and cmax, because cmin will always be the same as c1, and cmax will always be the same as c2.  So it happens to work within this routine, using c1 and c2 instead of cmin and cmax in the positional tests.  But if the routine were adjusted so that the User could do it left-to-right or right-to-left, or if c1 & c2 were picked points that might be in any relationship, or were extracted from the endpoints of a Line that might run in any direction, the version that uses c1 and c2 in those tests would sometimes not find the Points.

 

But in any case, the (ssget) approach with positional tests, just as (ssget) with a Window, has the potential to find Point entities that fall within the given area but that are not part of the result of the Measure command.  If there might ever be any of those, the approach of finding all entities that are newer than the result of the Mirror command, rather than using positional tests, will be more reliable.

Kent Cooper, AIA
Message 9 of 10
Kent1Cooper
in reply to: bkp


@Bkp wrote:

.... 

....
(command "mirror" "l" "" c5 c8 "") (command "measure" "l" p1)

 

In that, I want to make a selection set of points made by measure command.

....


Another way to do it, if the Measure command is always applied to a Line entity -- two-point Fence selection:

 

....

(command "mirror" "l" "" c5 c8 "")
(setq ldata (entget (entlast))); Line's entity data
(command "_.measure" (entlast) p1); ["l" was giving me an error -- version-dependent, maybe]
(setq ss (ssget "_F" (list (cdr (assoc 10 ldata)) (cdr (assoc 11 ldata))) '((0 . "POINT")))); Line's endpoints for Fence

 

That also has the potential to find unwanted Point entities, but they would need to lie exactly on that last Line for it to find them, which seems less likely than for there to be any within a rectangular area.

Kent Cooper, AIA
Message 10 of 10
bkp
Contributor
in reply to: Kent1Cooper

Thanks for the reply Mr. Cooper.

 

I tried all the help provided by you. But in making the selection set, I forgot that copy command doesn’t apply to the selection set. (please correct me if I am wrong).

 

So I had to give up that idea of making a selection set of points for this file. Here is the latest file.

(vmon)
(defun c:tus ()

;(alert "Please turn CAPS on")
  (setq c1 (getpoint "Pick Bottom Left Point: "))
  (setq l1 (getreal "Enter Length of Truss: "))
  (setq h1 (getreal "Enter Height of Truss at the Centre: "))
  (setq h2 (getreal "Enter Height of Truss at Support: "))
  (setq p1 (getreal "Enter Purlin Distance: "))
  (setq osm (getvar "osmode"))
  (setvar "osmode" 0)
  (setq c2 (list (+ (car c1) l1) (cadr c1)))
  (setq c3 (list (car c1) (+ (cadr c1) h2)))
  (setq c4 (list (car c2) (+ (cadr c2) h2)))
  (setq c6 (list (- (car c1) 200) (cadr c1)))
  (setq c7 (list (car c1) (- (cadr c1) 200)))
  (setq c8 (list (+ (car c1) (/ l1 2)) (cadr c1)))
  (setq c5 (list (+ (car c1) (/ l1 2)) (+ (cadr c1) h1)))
  (setq c11 (list (car c2) (- (cadr c2) 25)))
  (setq c12 (list (car c2) (- (cadr c2) h1)))
  (setq c13 (list (car c1) (- (cadr c1) 25)))
  (setq c14 (list (car c1) (- (cadr c1) h1)))
  (setq h3 (- h1 h2))
  (setq h4 (/ l1 2))

  (setq rad (angle c4 c5))
  (setq h5 (* (+ p1 115) (sin rad)))
  (setq h6 (* (+ p1 115) (cos rad)))

  (setq c9 (list (+ (car c5) h6) (- (cadr c5) h5)))

  (setq h7 (* p1 (sin rad)))
  (setq h8 (* p1 (cos rad)))

  (setq c10 (list (+ (car c9) h8) (- (cadr c9) h7)))

  (setq l1 (fix (/ h4 p1)))

  (command "layer" "s" "dim" "")
  (command "dim1" "ver" c1 c3 c6 "")
  (command "dim1" "hor" c1 c2 c7 "")

  (command "layer" "s" "center2" "")
  (command "pline" c1 c2 c4 c5 c3 "c")
  (command "explode" "l" "")

  (command "layer" "s" "0" "")
  (command "line" c8 c5 "")

  (command "copy" "l" "" c5 c9 "")
  (command "copy" "l" "" c9 c10 "")
  (setq x (- l1 2))

  (repeat x
    (command "copy" "l" "" c9 c10 "")
  )

  (setq ab (ssget "x" '((8 . "0") (0 . "LINE"))))  

  (command "mirror" ab "" c8 c5 "")

  (setq ac (ssget "x" '((8 . "0") (0 . "LINE"))))

  (command "change" ac "" "p" "la" "center2" "")

  (command "trim" "" "crossing" c11 c12 c13 c14 "")

  (command "layer" "s" "center2" "")
  (setvar "osmode" osm)
)

 

I am still stuck in the maths as diagonals are still pending in this file.

 

I am also sending you the file where I made some blunders.

(vmon)
(defun c:tus()

;(alert "Please turn CAPS on")
(setq c1 (getpoint "Pick Bottom Left Point: "))
(setq l1 (getreal "Enter Length of Truss: "))
(setq h1 (getreal "Enter Height of Truss at the Centre: "))
(setq h2 (getreal "Enter Height of Truss at Support: "))
(setq p1 (getreal "Enter Purlin Distance: "))
(setq osm (getvar "osmode"))
(setvar "osmode" 0)
(setq c2 (list (+ (car c1) l1) (cadr c1)))
(setq c3 (list (car c1) (+ (cadr c1) h2)))
(setq c4 (list (car c2) (+ (cadr c2) h2)))
(setq c6 (list (- (car c1) 200) (cadr c1)))
(setq c7 (list (car c1) (- (cadr c1) 200)))
(setq c8 (list (+ (car c1) (/ l1 2)) (cadr c1)))
(setq c5 (list (+ (car c1) (/ l1 2)) (+ (cadr c1) h1)))
(setq
  ss (ssadd); start with empty selection set
  ent (entlast); reference start-point
); setq


(command "layer" "s" "dim" "")
(command "dim1" "ver" c1 c3 c6 "")
(command "dim1" "hor" c1 c2 c7 "")

(command "layer" "s" "center2" "")
(command "line" c1 c3 "")
(command "copy" "l" "" c1 c2 "")
(command "line" c1 c2 "")
(command "line" c8 c5 "")
(setq aa "l")
(command "line" c3 c5 "")

(command "mirror" "l" "" c5 c8 "")

(command "measure" (entlast) p1 "")

(while (setq ent (entnext ent)); stepping through entities newer than the Mirrored one
       (ssadd ent ss)
       (command "copy" aa "" c5 ent "")
); while

;(command "array" "l" "" "r" l2 1 p1 "")

 
(setvar "osmode" osm)
)

 Please suggest what I shouldnt do next time.

 

Thanks for the knowledge shared on the subject by all of you.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost