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

Need help finishing a lisp routine.

20 REPLIES 20
Reply
Message 1 of 21
Anonymous
517 Views, 20 Replies

Need help finishing a lisp routine.

I have a lisp routine that I am trying to write, and could use some
input. This routine is designed to take a typical state section and
subdivide it into quarter-quarter sections, based on 4 user selected
points (4 corners of section). It will then draw a closed polygon around
1 of the 16 possible quarter-quarter sections that the user inputs.
Below is what I have written so far. If someone could please help me
finish it, it would be very appreciated.


--
Stan D. Bohnsack
WWC Engineering
1849 Terra Ave
Sheridan, Wy. 82801
(307) 672-0761




Watch for word wrap...


engqtr.LSP SDB 5/05

User picks the four corners of a typical land section, then
the routine sub-divides the area and draws individual quarter-quarter
sections depending on user input.

(defun C:engqtr ( / asnp,osm,p1,p2,p3,p4)
(setq asnp (getvar "autosnap"))
(setq osm (getvar "osmode"))
(setvar "osmode" 33)
(setq p1 (getpoint "\nPick northwest corner of section:...")) (TERPRI)
(setq p2 (getpoint "\nPick northeast corner of section:...")) (TERPRI)
(setq p3 (getpoint "\nPick southwest corner of section:...")) (TERPRI)
(setq p4 (getpoint "\nPick southeast corner of section:...")) (TERPRI)
(setq NUM (getint "\nEnter numeric value of Q/Q section to be
drawn:..(1-16)"))
(setvar "autosnap" asnp)
(setvar "osmode" 0)
(setq
p1x (car p1)
p2x (car p2)
p12x (/ (+ p2x p1x) 2)
p1y (cadr p1)
p2y (cadr p2)
p12y (/ (+ p2y p1y) 2)
q1 (list p12x p12y)
p3x (car p3)
p4x (car p4)
p3y (cadr p3)
p4y (cadr p4)
p34x (/ (+ p4x p3x) 2)
p34y (/ (+ p4y p3y) 2)
q2 (list p34x p34y)
p13x (/ (+ p3x p1x) 2)
p13y (/ (+ p3y p1y) 2)
q3 (list p13x p13y)
p24x (/ (+ p4x p2x) 2)
p24y (/ (+ p4y p2y) 2)
q4 (list p24x p24y)
qq1x (/ (+ q1x p1x) 2)
qq1y (/ (+ q1y p1y) 2)
qq1 (list qq1x qq1y)
qq2x (/ (+ q2x p3x) 2)
qq2y (/ (+ q2y p3y) 2)
qq2 (list qq2x qq2y)
qq3x (/ (+ p2x q1x) 2)
qq3y (/ (+ p2y q1y) 2)
qq3 (list qq3x qq3y)
qq4x (/ (+ p4x q2x) 2)
qq4y (/ (+ p4y q2y) 2)
qq4 (list qq4x qq4y)
qq5x (/ (+ q3x p1x) 2)
qq5y (/ (+ q3y p1y) 2)
qq5 (list qq5x qq5y)
qq6x (/ (+ q4x p2x) 2)
qq6y (/ (+ q4y p2y) 2)
qq6 (list qq6x qq6y)
qq7x (/ (+ p3x q3x) 2)
qq7y (/ (+ p3y q3y) 2)
qq7 (list qq7x qq7y)
qq8x (/ (+ p4x q4x) 2)
qq8y (/ (+ p4y q4y) 2)
qq8 (list qq8x qq8y)
cp1x (/ (+ q2x q1x) 2)
cp1y (/ (+ q2y q1y) 2)
cp1 (list cp1x cp1y)
cp2x (/ (+ qq2x qq1x) 2)
cp2y (/ (+ qq2y qq1y) 2)
cp2 (list cp2x cp2y)
cp3x (/ (+ qq4x qq3x) 2)
cp3y (/ (+ qq4y qq3y) 2)
cp3 (list cp3x cp3y)
cp4x (/ (+ cp1x q1x) 2)
cp4y (/ (+ cp1y q1y) 2)
cp4 (list cp4x cp4y)
cp5x (/ (+ cp2x qq1x) 2)
cp5y (/ (+ cp2y qq1y) 2)
cp5 (list cp5x cp5y)
cp6x (/ (+ cp3x qq3x) 2)
cp6y (/ (+ cp3y qq3y) 2)
cp6 (list cp6x cp6y)
cp7x (/ (+ q2x cp1x) 2)
cp7y (/ (+ q2y cp1y) 2)
cp7 (list cp7x cp7y)
cp8x (/ (+ qq2x cp2x) 2)
cp8y (/ (+ qq2y cp2y) 2)
cp8 (list cp8x cp8y)
cp9x (/ (+ qq4x cp3x) 2)
cp9y (/ (+ qq4y cp3y) 2)
cp9 (list cp9x cp9y)
)

(If (= NUM 1)
(COMMAND "PLINE" p2 qq3 cp6 qq6 p2 "")
)
(If (= NUM 2)
(command "PLINE" qq3 q1 cp4 cp6 qq3 "")
)
(If (= NUM 3)
(command "PLINE" cp6 cp4 cp1 cp3 cp6 "")
)
(If (= NUM 4)
(command "PLINE" qq6 cp6 cp3 q4 qq6 "")
)
(If (= NUM 5)
(command "PLINE" q1 qq1 cp5 cp4 q1 "")
)
(If (= NUM 6)
(command "PLINE" qq1 p1 qq5 cp5 qq1 "")
)
(If (= NUM 7)
(command "PLINE" cp5 qq5 q3 cp2 cp5 "")
)
(If (= NUM 😎
(command "PLINE" cp4 cp5 cp2 cp1 cp4 "")
)
(If (= NUM 9)
(command "PLINE" cp1 cp2 cp8 cp7 cp1 "")
)
(If (= NUM 10)
(command "PLINE" cp2 q3 qq7 cp8 cp2 "")
)
(If (= NUM 11)
(command "PLINE" cp8 qq7 p3 qq2 cp8 "")
)
(If (= NUM 12)
(command "PLINE" cp7 cp8 qq2 q2 cp7 "")
)
(If (= NUM 13)
(command "PLINE" q4 cp3 cp9 qq8 q4 "")
)
(If (= NUM 14)
(command "PLINE" cp3 cp1 cp7 cp9 cp3 "")
)
(If (= NUM 15)
(command "PLINE" cp9 cp7 q2 qq4 cp9 "")
)
(If (= NUM 16)
(command "PLINE" qq8 cp9 qq4 p4 qq8 "")
)
)
20 REPLIES 20
Message 2 of 21
Anonymous
in reply to: Anonymous

How about this? I used the quadrant system rather than 1-16, so the user
enter 1-4 for the base quadrant the 1-4 for the sub quadrant. I also based
it on a closed LWPline defining the section boundary that consists of 4
points, it should probably be modified to allow a 5 vertex pline where the
5th vertex is identical to the starting vertex (the user manually closed the
pline).

Enjoy!
[code]
;| Command to draw the 1/4, 1/4 section of a known section. User enters
a number 1, 2, 3 or 4 for the NE, SE, SW, NW quadrant of both quarters.
For instance, user enters 1 & 3 and the southwest 1/4 of the northeast
1/4 of the section will be drawn.
Sparked by idea from Stan Bohnsack.
Authored by Jeff Mishler - April 23, 2005
|;
(defun c:qqsec (/ centerne centernw centerse centersect centersw coords
east-ang east-len eastcenter eastnorth eastsouth ne-sect
north-ang north-len northcenter northeast northwest nw-ne
nw-sect p1 p2 p3 p4 prmt qtr quad se-ne se-sect sect sect_data
south-ang south-len southcenter southeast southwest sw-nw sw-se
sw-sect west-ang west-len westcenter westnorth westsouth)
(and (setq sect (car (entsel)))
(setq sect_data (entget sect))
(eq (cdr (assoc 0 sect_data)) "LWPOLYLINE")
(= (cdr (assoc 90 sect_data)) 4)
(progn
(princ "\n Use NE=1, SE=2, SW=3, NW=4 for quadrant & section.....")
(initget 7 "1 2 3 4")
(setq quad (atoi (getkword "\nWhich quadrant? {1-4}: ")))
(initget 7 "1 2 3 4")
(setq qtr (atoi (getkword "\nWhich quarter? {1-4}: ")))
)
(setq coords (list (vlax-curve-getpointatparam sect 0)
(vlax-curve-getpointatparam sect 1)
(vlax-curve-getpointatparam sect 2)
(vlax-curve-getpointatparam sect 3)
))
(setq coords (vl-sort coords '(lambda (x y)
(< (car x) (car y)))))
(if (< (cadar coords)(cadr (car (cdr coords))))
(setq sw-sect (car coords)
nw-sect (car (cdr coords))
)
(setq nw-sect (car coords)
sw-sect (car (cdr coords))
)
)
(setq coords (vl-sort coords '(lambda (x y)
(> (car x) (car y)))))
(if (> (cadar coords)(cadr (car (cdr coords))))
(setq ne-sect (car coords)
se-sect (car (cdr coords))
)
(setq se-sect (car coords)
ne-sect (car (cdr coords))
)
)
(setq west-len (distance sw-sect nw-sect)
north-len (distance nw-sect ne-sect)
east-len (distance ne-sect se-sect)
south-len (distance se-sect sw-sect)
west-ang (angle sw-sect nw-sect)
north-ang (angle nw-sect ne-sect)
east-ang (angle se-sect ne-sect)
south-ang (angle sw-sect se-sect)
)
(setq westsouth (polar sw-sect west-ang (/ west-len 4))
westcenter (polar sw-sect west-ang (/ west-len 2))
westnorth (polar westcenter west-ang (/ west-len 4))
northwest (polar nw-sect north-ang (/ north-len 4))
northcenter (polar nw-sect north-ang (/ north-len 2))
northeast (polar northcenter north-ang (/ north-len 4))
southwest (polar sw-sect south-ang (/ south-len 4))
southcenter (polar sw-sect south-ang (/ south-len 2))
southeast (polar southcenter south-ang (/ south-len 4))
eastsouth (polar se-sect east-ang (/ east-len 4))
eastcenter (polar se-sect east-ang (/ east-len 2))
eastnorth (polar eastcenter east-ang (/ east-len 4))
centersect (inters westcenter eastcenter southcenter northcenter)
centerne (inters westnorth eastnorth southeast northeast)
centerse (inters westsouth eastsouth southeast northeast)
centersw (inters westsouth eastsouth southwest northwest)
centernw (inters westnorth eastnorth southwest northwest)
se-ne (inters westcenter eastcenter southeast northeast)
sw-se (inters westsouth eastsouth southcenter northcenter)
sw-nw (inters westcenter eastcenter southwest northwest)
nw-ne (inters westnorth eastnorth southcenter northcenter)
)
(cond ((= 1 quad)
(cond ((= 1 qtr)(setq p1 ne-sect
p2 eastnorth
p3 centerne
p4 northeast)
(setq prmt "\nNortheast 1/4 of Northeast 1/4 created....."))
((= 2 qtr) (setq p1 eastnorth
p2 eastcenter
p3 se-ne
p4 centerne)
(setq prmt "\nSoutheast 1/4 of Northeast 1/4 created....."))
((= 3 qtr) (setq p1 centerne
p2 se-ne
p3 centersect
p4 nw-ne)
(setq prmt "\nSouthwest 1/4 of Northeast 1/4 created....."))
(t (setq p1 northeast
p2 centerne
p3 nw-ne
p4 northcenter)
(setq prmt "\nNorthwest 1/4 of Northeast 1/4 created....."))
)
)
((= 2 quad)
(cond ((= 1 qtr)(setq p1 eastcenter
p2 eastsouth
p3 centerse
p4 se-ne)
(setq prmt "\nNortheast 1/4 of Southeast 1/4 created....."))
((= 2 qtr) (setq p1 eastsouth
p2 se-sect
p3 southeast
p4 centerse)
(setq prmt "\nSoutheast 1/4 of Southeast 1/4 created....."))
((= 3 qtr) (setq p1 centerse
p2 southeast
p3 southcenter
p4 sw-se)
(setq prmt "\nSouthwest 1/4 of Southeast 1/4 created....."))
(t (setq p1 se-ne
p2 centerse
p3 sw-se
p4 centersect)
(setq prmt "\nNorthwest 1/4 of Southeast 1/4 created....."))
)
)
((= 3 quad)
(cond ((= 1 qtr)(setq p1 centersect
p2 sw-se
p3 centersw
p4 sw-nw)
(setq prmt "\nNortheast 1/4 of Southwest 1/4 created....."))
((= 2 qtr) (setq p1 sw-se
p2 southcenter
p3 southwest
p4 centersw)
(setq prmt "\nSoutheast 1/4 of Southwest 1/4 created....."))
((= 3 qtr) (setq p1 centersw
p2 southwest
p3 sw-sect
p4 westsouth)
(setq prmt "\nSouthwest 1/4 of Southwest 1/4 created....."))
(t (setq p1 centersw
p2 westsouth
p3 westcenter
p4 sw-nw)
(setq prmt "\nNorthwest 1/4 of Southwest 1/4 created....."))
)
)
((= 4 quad)
(cond ((= 1 qtr)(setq p1 northcenter
p2 nw-ne
p3 centernw
p4 northwest)
(setq prmt "\nNortheast 1/4 of Northwest 1/4 created....."))
((= 2 qtr) (setq p1 nw-ne
p2 centersect
p3 sw-nw
p4 centernw)
(setq prmt "\nSoutheast 1/4 of Northwest 1/4 created....."))
((= 3 qtr) (setq p1 centernw
p2 sw-nw
p3 westcenter
p4 westnorth)
(setq prmt "\nSouthwest 1/4 of Northwest 1/4 created....."))
(t (setq p1 northwest
p2 centernw
p3 westnorth
p4 nw-sect)
(setq prmt "\nNorthwest 1/4 of Northwest 1/4 created....."))
)
)
)
(command "pline" p1 p2 p3 p4 "c")
)
(if prmt
(princ prmt)
)
(princ)
)
[/code]

--
Jeff
check out www.cadvault.com
"Stan Bohnsack" wrote in message
news:4823898@discussion.autodesk.com...
>I have a lisp routine that I am trying to write, and could use some
> input. This routine is designed to take a typical state section and
> subdivide it into quarter-quarter sections, based on 4 user selected
> points (4 corners of section). It will then draw a closed polygon around
> 1 of the 16 possible quarter-quarter sections that the user inputs.
> Below is what I have written so far. If someone could please help me
> finish it, it would be very appreciated.
>
>
> --
> Stan D. Bohnsack
> WWC Engineering
> 1849 Terra Ave
> Sheridan, Wy. 82801
> (307) 672-0761
>
>
>
>
> Watch for word wrap...
>
>
> engqtr.LSP SDB 5/05
>
> User picks the four corners of a typical land section, then
> the routine sub-divides the area and draws individual quarter-quarter
> sections depending on user input.
>
> (defun C:engqtr ( / asnp,osm,p1,p2,p3,p4)
> (setq asnp (getvar "autosnap"))
> (setq osm (getvar "osmode"))
> (setvar "osmode" 33)
> (setq p1 (getpoint "\nPick northwest corner of section:...")) (TERPRI)
> (setq p2 (getpoint "\nPick northeast corner of section:...")) (TERPRI)
> (setq p3 (getpoint "\nPick southwest corner of section:...")) (TERPRI)
> (setq p4 (getpoint "\nPick southeast corner of section:...")) (TERPRI)
> (setq NUM (getint "\nEnter numeric value of Q/Q section to be
> drawn:..(1-16)"))
> (setvar "autosnap" asnp)
> (setvar "osmode" 0)
> (setq
> p1x (car p1)
> p2x (car p2)
> p12x (/ (+ p2x p1x) 2)
> p1y (cadr p1)
> p2y (cadr p2)
> p12y (/ (+ p2y p1y) 2)
> q1 (list p12x p12y)
> p3x (car p3)
> p4x (car p4)
> p3y (cadr p3)
> p4y (cadr p4)
> p34x (/ (+ p4x p3x) 2)
> p34y (/ (+ p4y p3y) 2)
> q2 (list p34x p34y)
> p13x (/ (+ p3x p1x) 2)
> p13y (/ (+ p3y p1y) 2)
> q3 (list p13x p13y)
> p24x (/ (+ p4x p2x) 2)
> p24y (/ (+ p4y p2y) 2)
> q4 (list p24x p24y)
> qq1x (/ (+ q1x p1x) 2)
> qq1y (/ (+ q1y p1y) 2)
> qq1 (list qq1x qq1y)
> qq2x (/ (+ q2x p3x) 2)
> qq2y (/ (+ q2y p3y) 2)
> qq2 (list qq2x qq2y)
> qq3x (/ (+ p2x q1x) 2)
> qq3y (/ (+ p2y q1y) 2)
> qq3 (list qq3x qq3y)
> qq4x (/ (+ p4x q2x) 2)
> qq4y (/ (+ p4y q2y) 2)
> qq4 (list qq4x qq4y)
> qq5x (/ (+ q3x p1x) 2)
> qq5y (/ (+ q3y p1y) 2)
> qq5 (list qq5x qq5y)
> qq6x (/ (+ q4x p2x) 2)
> qq6y (/ (+ q4y p2y) 2)
> qq6 (list qq6x qq6y)
> qq7x (/ (+ p3x q3x) 2)
> qq7y (/ (+ p3y q3y) 2)
> qq7 (list qq7x qq7y)
> qq8x (/ (+ p4x q4x) 2)
> qq8y (/ (+ p4y q4y) 2)
> qq8 (list qq8x qq8y)
> cp1x (/ (+ q2x q1x) 2)
> cp1y (/ (+ q2y q1y) 2)
> cp1 (list cp1x cp1y)
> cp2x (/ (+ qq2x qq1x) 2)
> cp2y (/ (+ qq2y qq1y) 2)
> cp2 (list cp2x cp2y)
> cp3x (/ (+ qq4x qq3x) 2)
> cp3y (/ (+ qq4y qq3y) 2)
> cp3 (list cp3x cp3y)
> cp4x (/ (+ cp1x q1x) 2)
> cp4y (/ (+ cp1y q1y) 2)
> cp4 (list cp4x cp4y)
> cp5x (/ (+ cp2x qq1x) 2)
> cp5y (/ (+ cp2y qq1y) 2)
> cp5 (list cp5x cp5y)
> cp6x (/ (+ cp3x qq3x) 2)
> cp6y (/ (+ cp3y qq3y) 2)
> cp6 (list cp6x cp6y)
> cp7x (/ (+ q2x cp1x) 2)
> cp7y (/ (+ q2y cp1y) 2)
> cp7 (list cp7x cp7y)
> cp8x (/ (+ qq2x cp2x) 2)
> cp8y (/ (+ qq2y cp2y) 2)
> cp8 (list cp8x cp8y)
> cp9x (/ (+ qq4x cp3x) 2)
> cp9y (/ (+ qq4y cp3y) 2)
> cp9 (list cp9x cp9y)
> )
>
> (If (= NUM 1)
> (COMMAND "PLINE" p2 qq3 cp6 qq6 p2 "")
> )
> (If (= NUM 2)
> (command "PLINE" qq3 q1 cp4 cp6 qq3 "")
> )
> (If (= NUM 3)
> (command "PLINE" cp6 cp4 cp1 cp3 cp6 "")
> )
> (If (= NUM 4)
> (command "PLINE" qq6 cp6 cp3 q4 qq6 "")
> )
> (If (= NUM 5)
> (command "PLINE" q1 qq1 cp5 cp4 q1 "")
> )
> (If (= NUM 6)
> (command "PLINE" qq1 p1 qq5 cp5 qq1 "")
> )
> (If (= NUM 7)
> (command "PLINE" cp5 qq5 q3 cp2 cp5 "")
> )
> (If (= NUM 😎
> (command "PLINE" cp4 cp5 cp2 cp1 cp4 "")
> )
> (If (= NUM 9)
> (command "PLINE" cp1 cp2 cp8 cp7 cp1 "")
> )
> (If (= NUM 10)
> (command "PLINE" cp2 q3 qq7 cp8 cp2 "")
> )
> (If (= NUM 11)
> (command "PLINE" cp8 qq7 p3 qq2 cp8 "")
> )
> (If (= NUM 12)
> (command "PLINE" cp7 cp8 qq2 q2 cp7 "")
> )
> (If (= NUM 13)
> (command "PLINE" q4 cp3 cp9 qq8 q4 "")
> )
> (If (= NUM 14)
> (command "PLINE" cp3 cp1 cp7 cp9 cp3 "")
> )
> (If (= NUM 15)
> (command "PLINE" cp9 cp7 q2 qq4 cp9 "")
> )
> (If (= NUM 16)
> (command "PLINE" qq8 cp9 qq4 p4 qq8 "")
> )
> )
Message 3 of 21
Anonymous
in reply to: Anonymous

Stan and Jeff,

Just an example of an alternate method. Needs a little more thought up front and a
bit less code. 🙂

Joe Burke

[code]
;; Divide a rectangle into 16 sections and place
;; a subsection at position as follows:
;; 13 14 15 16
;; 9 10 11 12
;; 5 6 7 8
;; 1 2 3 4
;; Note: use in WCS.
(defun c:16Sections ( / num obj p1 p2 mn mx xd yd )
(while (not (< 0 num 17))
(setq num (getint "\nEnter number from 1 to 16: "))
)
(while
(or
(not (setq obj (car (entsel "\nSelect rectangular pline: "))))
(not (eq "AcDbPolyline" (vlax-get
(setq obj (vlax-ename->vla-object obj)) 'ObjectName)))
)
(princ "\nMissed pick or wrong object type. ")
)
(vla-getboundingbox obj 'mn 'mx)
(setq p1 (vlax-safearray->list mn))
(setq p2 (vlax-safearray->list mx))
(setq xd (/ (- (car p2) (car p1)) 4))
(setq yd (/ (- (cadr p2) (cadr p1)) 4))
(cond
((< num 5)
(repeat (1- num)
(setq p1 (list (+ xd (car p1)) (cadr p1)))
)
)
((< num 9)
(setq p1 (list (car p1) (+ yd (cadr p1))))
(repeat (- num 5)
(setq p1 (list (+ xd (car p1)) (cadr p1)))
)
)
((< num 13)
(setq p1 (list (car p1) (+ (* yd 2) (cadr p1))))
(repeat (- num 9)
(setq p1 (list (+ xd (car p1)) (cadr p1)))
)
)
((< num 17)
(setq p1 (list (car p1) (+ (* yd 3) (cadr p1))))
(repeat (- num 13)
(setq p1 (list (+ xd (car p1)) (cadr p1)))
)
)
)
(setq p2 (list (+ xd (car p1)) (+ yd (cadr p1))))
(setq osm (getvar "osmode"))
(setvar "osmode" 0)
(command "_rectang" p1 p2)
(setvar "osmode" osm)
(princ)
)
[/code]
Message 4 of 21
Anonymous
in reply to: Anonymous

Hi Joe,
One minor problem with your code.......a Section is never rectangular, or
even square as it should be, but rather an irregular trapezoid. That's why I
needed to define each node individually.

--
Jeff
check out www.cadvault.com
"Joe Burke" wrote in message
news:4824239@discussion.autodesk.com...
> Stan and Jeff,
>
> Just an example of an alternate method. Needs a little more thought up
> front and a bit less code. 🙂
>
> Joe Burke
>
> [code]
> ;; Divide a rectangle into 16 sections and place
> ;; a subsection at position as follows:
> ;; 13 14 15 16
> ;; 9 10 11 12
> ;; 5 6 7 8
> ;; 1 2 3 4
> ;; Note: use in WCS.
> (defun c:16Sections ( / num obj p1 p2 mn mx xd yd )
> (while (not (< 0 num 17))
> (setq num (getint "\nEnter number from 1 to 16: "))
> )
> (while
> (or
> (not (setq obj (car (entsel "\nSelect rectangular pline: "))))
> (not (eq "AcDbPolyline" (vlax-get
> (setq obj (vlax-ename->vla-object obj)) 'ObjectName)))
> )
> (princ "\nMissed pick or wrong object type. ")
> )
> (vla-getboundingbox obj 'mn 'mx)
> (setq p1 (vlax-safearray->list mn))
> (setq p2 (vlax-safearray->list mx))
> (setq xd (/ (- (car p2) (car p1)) 4))
> (setq yd (/ (- (cadr p2) (cadr p1)) 4))
> (cond
> ((< num 5)
> (repeat (1- num)
> (setq p1 (list (+ xd (car p1)) (cadr p1)))
> )
> )
> ((< num 9)
> (setq p1 (list (car p1) (+ yd (cadr p1))))
> (repeat (- num 5)
> (setq p1 (list (+ xd (car p1)) (cadr p1)))
> )
> )
> ((< num 13)
> (setq p1 (list (car p1) (+ (* yd 2) (cadr p1))))
> (repeat (- num 9)
> (setq p1 (list (+ xd (car p1)) (cadr p1)))
> )
> )
> ((< num 17)
> (setq p1 (list (car p1) (+ (* yd 3) (cadr p1))))
> (repeat (- num 13)
> (setq p1 (list (+ xd (car p1)) (cadr p1)))
> )
> )
> )
> (setq p2 (list (+ xd (car p1)) (+ yd (cadr p1))))
> (setq osm (getvar "osmode"))
> (setvar "osmode" 0)
> (command "_rectang" p1 p2)
> (setvar "osmode" osm)
> (princ)
> )
> [/code]
Message 5 of 21
Anonymous
in reply to: Anonymous

Hi Jeff,

Actually I thought a section was a square, like a square mile. Allowing rectangles
only added an extra variable.

Goes to show what I know...

Joe


"Jeff Mishler" wrote in message
news:4824254@discussion.autodesk.com...
> Hi Joe,
> One minor problem with your code.......a Section is never rectangular, or even
> square as it should be, but rather an irregular trapezoid. That's why I needed to
> define each node individually.
>
> --
> Jeff
> check out www.cadvault.com
> "Joe Burke" wrote in message
> news:4824239@discussion.autodesk.com...
>> Stan and Jeff,
>>
>> Just an example of an alternate method. Needs a little more thought up front and a
>> bit less code. 🙂
>>
>> Joe Burke
>>
>> [code]
>> ;; Divide a rectangle into 16 sections and place
>> ;; a subsection at position as follows:
>> ;; 13 14 15 16
>> ;; 9 10 11 12
>> ;; 5 6 7 8
>> ;; 1 2 3 4
>> ;; Note: use in WCS.
>> (defun c:16Sections ( / num obj p1 p2 mn mx xd yd )
>> (while (not (< 0 num 17))
>> (setq num (getint "\nEnter number from 1 to 16: "))
>> )
>> (while
>> (or
>> (not (setq obj (car (entsel "\nSelect rectangular pline: "))))
>> (not (eq "AcDbPolyline" (vlax-get
>> (setq obj (vlax-ename->vla-object obj)) 'ObjectName)))
>> )
>> (princ "\nMissed pick or wrong object type. ")
>> )
>> (vla-getboundingbox obj 'mn 'mx)
>> (setq p1 (vlax-safearray->list mn))
>> (setq p2 (vlax-safearray->list mx))
>> (setq xd (/ (- (car p2) (car p1)) 4))
>> (setq yd (/ (- (cadr p2) (cadr p1)) 4))
>> (cond
>> ((< num 5)
>> (repeat (1- num)
>> (setq p1 (list (+ xd (car p1)) (cadr p1)))
>> )
>> )
>> ((< num 9)
>> (setq p1 (list (car p1) (+ yd (cadr p1))))
>> (repeat (- num 5)
>> (setq p1 (list (+ xd (car p1)) (cadr p1)))
>> )
>> )
>> ((< num 13)
>> (setq p1 (list (car p1) (+ (* yd 2) (cadr p1))))
>> (repeat (- num 9)
>> (setq p1 (list (+ xd (car p1)) (cadr p1)))
>> )
>> )
>> ((< num 17)
>> (setq p1 (list (car p1) (+ (* yd 3) (cadr p1))))
>> (repeat (- num 13)
>> (setq p1 (list (+ xd (car p1)) (cadr p1)))
>> )
>> )
>> )
>> (setq p2 (list (+ xd (car p1)) (+ yd (cadr p1))))
>> (setq osm (getvar "osmode"))
>> (setvar "osmode" 0)
>> (command "_rectang" p1 p2)
>> (setvar "osmode" osm)
>> (princ)
>> )
>> [/code]
Message 6 of 21
Anonymous
in reply to: Anonymous

This might help (Watch out for word wrap!)...

(defun C:engqtr ( / *error* asnp cmdecho osm interp
p1 p2 p3 p4 Num
Long1 Long2 Lat1 Lat2
N1 N2 E1 E2 S1 S2 W1 W2)
(setq asnp (getvar "autosnap")
cmdecho (getvar "cmdecho")
osm (getvar "osmode")
)
(defun *error* (msg)
(setvar "autosnap" asnp)
(setvar "cmdecho" cmdecho)
(setvar "osmode" osm)
(cond
((not msg))
((wcmatch (strcase msg) "*CANCEL*,*QUIT*"))
(princ (strcat "\nERROR: " msg))
)
(princ)
)
(defun interp (p1 p2 fract)
(mapcar '+ p1 (mapcar '* (mapcar '- p2 p1)(list fract fract fract)))
)
(setvar "osmode" 33)
(setvar "cmdecho" 0)
(and
(setq p1 (getpoint "\nPick NorthWest corner of section: "))
(setq p2 (getpoint "\nPick NorthEast corner of section: "))
(setq p3 (getpoint "\nPick SouthEast corner of section: "))
(setq p4 (getpoint "\nPick SouthEast corner of section: "))
(not
(initget 1
(strcat
" 1 2 3 4"
" 5 6 7 8"
" 9 10 11 12 "
"13 14 15 16"
)
)
)
(setq NUM (getkword "\nEnter numeric value of Q/Q section to be
drawn:..[1-16]: "))
(setq Num (atoi Num))
(setvar "autosnap" asnp)
(setvar "osmode" 0)
(cond
((member Num '(1 5 9 13))
(setq Long1 0.0 Long2 0.25)
)
((member Num '(2 6 10 14))
(setq Long1 0.25 Long2 0.50)
)
((member Num '(3 7 11 15))
(setq Long1 0.50 Long2 0.75)
)
((member Num '(4 8 12 16))
(setq Long1 0.75 Long2 1.00)
)
)
(cond
((member Num '(1 2 3 4))
(setq Lat1 0.0 Lat2 0.25)
)
((member Num '(5 6 7 8))
(setq Lat1 0.25 Lat2 0.50)
)
((member Num '(9 10 11 12))
(setq Lat1 0.50 Lat2 0.75)
)
((member Num '(13 14 15 16))
(setq Lat1 0.75 Lat2 1.00)
)
)
(setq N1 (interp p1 p2 Long1)
N2 (interp p1 p2 Long2)
S1 (interp p3 p4 Long1)
S2 (interp p3 p4 Long2)
W1 (interp p1 p3 Lat1)
W2 (interp p1 p3 Lat2)
E1 (interp p2 p4 Lat1)
E2 (interp p2 p4 Lat2)
)
(vl-cmdf "_.pline")
(vl-cmdf (inters N1 S1 W1 E1 nil)) ; NW
(vl-cmdf (inters N2 S2 W1 E1 nil)) ; NE
(vl-cmdf (inters N2 S2 W2 E2 nil)) ; SE
(vl-cmdf (inters N1 S1 W2 E2 nil)) ; SW
(vl-cmdf "_Close")
)
(*error* nil)
)


--
John Uhden, Cadlantic

http://www.cadlantic.com
Sea Girt, NJ

"Stan Bohnsack" wrote in message
news:4823898@discussion.autodesk.com...
> I have a lisp routine that I am trying to write, and could use some
> input. This routine is designed to take a typical state section and
> subdivide it into quarter-quarter sections, based on 4 user selected
> points (4 corners of section). It will then draw a closed polygon around
> 1 of the 16 possible quarter-quarter sections that the user inputs.
Message 7 of 21
Anonymous
in reply to: Anonymous

I'd appreciate it if someone would post a drawing here or in CF showing what a
typical Section looks like.

I'm not sure what Jeff means by an "irregular trapeziod". Guessing, does it mean a
four sided shape with two parallel sides and the other two sides have unequal
lengths? Versus a "regular" trapezoid where the two non parallel sides are equal in
length?

Obviously I'm clueless. Might as well learn something while stubbing my toes.

Thanks
Joe
Message 8 of 21
Tom Smith
in reply to: Anonymous

My take was similar to John's. If you divide each edge of the section into quarters, and connect the dots with imaginary lines, you can find the corners of each quarter-quarter section as intersections of its four bounding lines.

It's easy enough to get an even division point along a line, for instance the nth quarter point from pt1 to pt2 is:

(defun qtrpnt (n pt1 pt2)
(polar pt1 (angle pt1 pt2) (* n (/ distance pt1 pt2) 4))))

Given the numbering system, you can figure the column and row number of a given q-q-section, as shown below. I'm calling the NW q-q-section (#13) column 0, row 0.

For instance, if you call the corners of the section nw, ne, se, sw, then the west edge of q-q-section #6 (column 1, row 2) would fall along the line from (qtrpnt 1 nw ne) to (qtrpnt 1 sw se), and so forth. With no error checking:

(defun c:qqs (/ nw ne se sw qqsect col row n-edge s-edge w-edge e-edge ptlist)
(setq
nw (getpoint "\nNW corner: ")
ne (getpoint "\nNE corner: ")
se (getpoint "\nSE corner: ")
sw (getpoint "\nSW corner: ")
qqsect (getint "\nQ/Q section number: ")
col (rem (1- qqsect) 4)
row (- 3 (/ (1- qqsect) 4))
n-edge (list (qtrpnt row nw sw) (qtrpnt row ne se))
s-edge (list (qtrpnt (1+ row) nw sw) (qtrpnt (1+ row) ne se))
w-edge (list (qtrpnt col nw ne) (qtrpnt col sw se))
e-edge (list (qtrpnt (1+ col) nw ne) (qtrpnt (1+ col) sw se))
ptlist (list
(apply 'inters (append w-edge n-edge)) ;nw corner
(apply 'inters (append e-edge n-edge)) ;ne corner
(apply 'inters (append e-edge s-edge)) ;se corner
(apply 'inters (append w-edge s-edge)))) ;sw corner
(command "pline")
(foreach n ptlist (command n))
(command "c")
(princ))
Message 9 of 21
Anonymous
in reply to: Anonymous

Hi, Tom.
You've got the right idea, and I like the row & col approach.
There was a missing paren before distance...
(defun qtrpnt (n pt1 pt2)
(polar pt1 (angle pt1 pt2) (* n (/ (distance pt1 pt2) 4)))
)
A Q/Q section number of 4 gave me what I thought should be 16. A Q/Q
section number of 16 gave me a diagonal at what I thought should be 4. No
problem... just a little tweaking will make it a very nice job!

--
John Uhden, Cadlantic

http://www.cadlantic.com
Sea Girt, NJ

wrote in message news:4824333@discussion.autodesk.com...
> My take was similar to John's. If you divide each edge of the section into
quarters, and connect the dots with imaginary lines, you can find the
corners of each quarter-quarter section as intersections of its four
bounding lines.
>
> It's easy enough to get an even division point along a line, for instance
the nth quarter point from pt1 to pt2 is:
>
> (defun qtrpnt (n pt1 pt2)
> (polar pt1 (angle pt1 pt2) (* n (/ distance pt1 pt2) 4))))
>
> Given the numbering system, you can figure the column and row number of a
given q-q-section, as shown below. I'm calling the NW q-q-section (#13)
column 0, row 0.
>
> For instance, if you call the corners of the section nw, ne, se, sw, then
the west edge of q-q-section #6 (column 1, row 2) would fall along the line
from (qtrpnt 1 nw ne) to (qtrpnt 1 sw se), and so forth. With no error
checking:
>
> (defun c:qqs (/ nw ne se sw qqsect col row n-edge s-edge w-edge e-edge
ptlist)
> (setq
> nw (getpoint "\nNW corner: ")
> ne (getpoint "\nNE corner: ")
> se (getpoint "\nSE corner: ")
> sw (getpoint "\nSW corner: ")
> qqsect (getint "\nQ/Q section number: ")
> col (rem (1- qqsect) 4)
> row (- 3 (/ (1- qqsect) 4))
> n-edge (list (qtrpnt row nw sw) (qtrpnt row ne se))
> s-edge (list (qtrpnt (1+ row) nw sw) (qtrpnt (1+ row) ne se))
> w-edge (list (qtrpnt col nw ne) (qtrpnt col sw se))
> e-edge (list (qtrpnt (1+ col) nw ne) (qtrpnt (1+ col) sw se))
> ptlist (list
> (apply 'inters (append w-edge n-edge)) ;nw corner
> (apply 'inters (append e-edge n-edge)) ;ne corner
> (apply 'inters (append e-edge s-edge)) ;se corner
> (apply 'inters (append w-edge s-edge)))) ;sw corner
> (command "pline")
> (foreach n ptlist (command n))
> (command "c")
> (princ))
Message 10 of 21
Anonymous
in reply to: Anonymous

Joe:
Check out "EngQtr (quarter-quarters)" in CF.

--
John Uhden, Cadlantic

http://www.cadlantic.com
Sea Girt, NJ

"Joe Burke" wrote in message
news:4824317@discussion.autodesk.com...
> I'd appreciate it if someone would post a drawing here or in CF showing
what a
> typical Section looks like.
>
> I'm not sure what Jeff means by an "irregular trapeziod". Guessing, does
it mean a
> four sided shape with two parallel sides and the other two sides have
unequal
> lengths? Versus a "regular" trapezoid where the two non parallel sides are
equal in
> length?
>
> Obviously I'm clueless. Might as well learn something while stubbing my
toes.
>
> Thanks
> Joe
Message 11 of 21
Tom Smith
in reply to: Anonymous

Thanks, John, I'll go back and correct the parenthesis. The parcel numbering layout is based on what Joe posted:

13 14 15 16
9 10 11 12
5 6 7 8
1 2 3 4

My first approach was upside down from that, e.g. numbered left to right and top to bottom. Just take out the -3 from the row calc to flip it vertically. That's why you're getting unexpected results on #4 and #16. Maybe the OP will clarify where they really should be?

This could probably be shortened a few lines with a mapcar, and eliminating a few variables, but every way I tried to abbreviate it, the code seemed to get less readable.
Message 12 of 21
Anonymous
in reply to: Anonymous

Thanks, John.

PS to Jeff... that ain't no trapezoid, irregular or otherwise. 🙂 The term
trapezium would apply. A four sided shape given sides are not equal in length and no
two sides are parallel.

Joe Burke

> Joe:
> Check out "EngQtr (quarter-quarters)" in CF.
>
> --
> John Uhden, Cadlantic
>
> http://www.cadlantic.com
> Sea Girt, NJ
Message 13 of 21
Anonymous
in reply to: Anonymous

Thanks to all for the support. John's code seemed to produce an output
closest to what I was looking for. Thanks again.



Stan Bohnsack wrote:
> I have a lisp routine that I am trying to write, and could use some
> input. This routine is designed to take a typical state section and
> subdivide it into quarter-quarter sections, based on 4 user selected
> points (4 corners of section). It will then draw a closed polygon around
> 1 of the 16 possible quarter-quarter sections that the user inputs.
> Below is what I have written so far. If someone could please help me
> finish it, it would be very appreciated.
>
>
Message 14 of 21
Tom Smith
in reply to: Anonymous

John, per the OP, apparently you had the numbering correct, I had it flipped. My row index should be just (/ (1- qqsect) 4). Also, I wasn't managing osnaps, so depending on the geometry, my routine could snap to some unlikely places when placing the polyline.
Message 15 of 21
Anonymous
in reply to: Anonymous

Just for future reference the "correct numbering" was as follows:

| 6 | 5 | 2 | 1 |
| 7 | 8 | 3 | 4 |
| 10 | 9 | 14 | 13 |
| 11 | 12 | 15 | 16 |

This is the wyoming state engineers standard quarter-quarter numbering
structure. Again, thank you John for your help. I was able to modify the
numbering in your code in order to fit my specific need.



Stan Bohnsack wrote:

> I have a lisp routine that I am trying to write, and could use some
> input. This routine is designed to take a typical state section and
> subdivide it into quarter-quarter sections, based on 4 user selected
> points (4 corners of section). It will then draw a closed polygon around
> 1 of the 16 possible quarter-quarter sections that the user inputs.
> Below is what I have written so far. If someone could please help me
> finish it, it would be very appreciated.
>
>
Message 16 of 21
Tom Smith
in reply to: Anonymous

Stan, thanks for clarifying. Out of curiosity, is that standard in other states? I searched all over the web for this, and couldn't find anything about standard numberings below the scales of townships and sections.
Message 17 of 21
Anonymous
in reply to: Anonymous

Tom,
As far as I can tell this numbering structure is only in use by the
Wyoming State Engineers Office for use with their searchable water
rights database. However it is possible that other states have adopted a
similiar numbering system.

Here is a link to the Wyoming SEO's website.
http://seo.state.wy.us/


Tom Smith wrote:

> Stan, thanks for clarifying. Out of curiosity, is that standard in other states? I searched all over the web for this, and couldn't find anything about standard numberings below the scales of townships and sections.
Message 18 of 21
Anonymous
in reply to: Anonymous

Thanks for the good news! God job picking up on the quasi 4x4 matrix and
adjusting it for your needs.

--
John Uhden, Cadlantic

http://www.cadlantic.com
Sea Girt, NJ

"Stan Bohnsack" wrote in message
news:4824771@discussion.autodesk.com...
> Thanks to all for the support. John's code seemed to produce an output
> closest to what I was looking for. Thanks again.
>
>
>
> Stan Bohnsack wrote:
> > I have a lisp routine that I am trying to write, and could use some
> > input. This routine is designed to take a typical state section and
> > subdivide it into quarter-quarter sections, based on 4 user selected
> > points (4 corners of section). It will then draw a closed polygon around
> > 1 of the 16 possible quarter-quarter sections that the user inputs.
> > Below is what I have written so far. If someone could please help me
> > finish it, it would be very appreciated.
> >
> >
Message 19 of 21
Anonymous
in reply to: Anonymous

Hi. Just out of curiosity, wouldn't it be easier for the
user of your code, to just pick a point inside of the
desired section rather than having to designate it by
number? It would seem to me that if you got the
input that way, the numbering system in use would
not be an issue.

Unless I'm missing something completely obvious, I would
approach the problem of acquiring the desired section
from the user graphically, by draiwng all of the divisions
using temporary vectors, and then just prompting for a
point inside the desired section, and then just compute
which section they chose from that point.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Stan Bohnsack" wrote in message news:4825031@discussion.autodesk.com...
> Tom,
> As far as I can tell this numbering structure is only in use by the
> Wyoming State Engineers Office for use with their searchable water
> rights database. However it is possible that other states have adopted a
> similiar numbering system.
>
> Here is a link to the Wyoming SEO's website.
> http://seo.state.wy.us/
>
>
> Tom Smith wrote:
>
>> Stan, thanks for clarifying. Out of curiosity, is that standard in other states? I searched all over the web for
>> this, and couldn't find anything about standard numberings below the scales of townships and sections.
Message 20 of 21
Anonymous
in reply to: Anonymous

Sorry, Joe. I've come to the conclusion that I really shouldn't try to
respond to posts after putting in 16+ hour days. I knew what I meant to say,
yet just couldn't find the proper term...so I used what had popped into my
foggy brain at the time.

Luckily, as of 5 minutes ago, that job is done. I'm off for some much needed
rest.... 😉

--
Jeff
check out www.cadvault.com
"Joe Burke" wrote in message
news:4824685@discussion.autodesk.com...
> Thanks, John.
>
> PS to Jeff... that ain't no trapezoid, irregular or otherwise. 🙂 The
> term trapezium would apply. A four sided shape given sides are not equal
> in length and no two sides are parallel.
>
> Joe Burke
>
>> Joe:
>> Check out "EngQtr (quarter-quarters)" in CF.
>>
>> --
>> John Uhden, Cadlantic
>>
>> http://www.cadlantic.com
>> Sea Girt, NJ

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

Post to forums  

Autodesk Design & Make Report

”Boost