Author Topic: Draw diagonal hatch lines in rectangle by pick  (Read 6823 times)

0 Members and 1 Guest are viewing this topic.

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: Draw diagonal hatch lines in rectangle by pick
« Reply #30 on: April 17, 2021, 10:49:59 AM »
Actually there is nothing special in the codes to make not to work as expected so here is a full test.

I assume that you used the second version from this post:
https://www.theswamp.org/index.php?topic=56680.msg604290#msg604290


Christina

  • Newt
  • Posts: 27
Re: Draw diagonal hatch lines in rectangle by pick
« Reply #31 on: April 17, 2021, 11:28:52 AM »
Hello Tharwat,

I reload the second code just in case!
Now gave an error after the third entry...
But don't mind I just press undo and can continue for longer time.
If I only get that error, then I better switch back to Acad 2021 to be on the safe side.

Hope you have a nice weekend and thank you!

Christina


Christina

  • Newt
  • Posts: 27
Re: Draw diagonal hatch lines in rectangle by pick
« Reply #32 on: April 17, 2021, 12:45:29 PM »
Hello Tharwat,

Think I can reproduce the error ...
Can you make a normal zigzag in these 2 squares?
With me that does not work even not with 1 zigzag!
If I turn a square 1/4 around, a normal zigzag will work well...   :smitten:

Christina

Christina

  • Newt
  • Posts: 27
Re: Draw diagonal hatch lines in rectangle by pick
« Reply #33 on: April 17, 2021, 01:37:12 PM »
Hello Tharwat,

Another one, if I click left at the top, the zigzag usually works.
If do the same on the bottom right will not work well ...
If everything works well for you, I will go back to Acad 2021!
Thank you to test it  :smitten:

Christina

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: Draw diagonal hatch lines in rectangle by pick
« Reply #34 on: April 17, 2021, 06:27:48 PM »
It would be a great idea to consider a few fees then I will develop it further based on your request, PM if you're interested.

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Draw diagonal hatch lines in rectangle by pick
« Reply #35 on: April 17, 2021, 07:03:38 PM »
Using the different method just added the use longest. Would appreciate if you could try it. It will work with trapezoid. used your dwg test63 to test just polar arrayed the 4 lines.

Code: [Select]
; segment rectangs with verts and X.
; By AlanH April 2021

(defun c:zigzag ( / oldsnap pt pt1 pt2 pt3 pt4 ang1 ang2 dist1 dist2 lst lst2 x y )

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setq pt (getpoint "\nPick point inside rectang "))

(command "bpoly" pt "")
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (entlast)))))
(command "erase" (entlast) "")

(setq pt1 (nth 0 co-ord)
  pt2 (nth 1 co-ord)
  pt3 (nth 2 co-ord)
  pt4 (nth 3 co-ord)
  ang1 (angle pt1 pt2)
  ang2 (angle pt4 pt3)
  dist1 (distance pt1 pt2)
  dist2 (distance pt4 pt3)
)

(if (> dist1 dist2)
(setq co-ord (list (nth 1 co-ord)(nth 2 co-ord)(nth 3 co-ord)(nth 0 co-ord)))
)


(setq num (getreal "\Enter number of segments "))

(setq lst '())
(setq lst2 '())

(setq x 1.0)
(repeat (- (fix num) 1)
(setq lst  (cons (polar pt1 ang1 (* dist1 (/ x num))) lst))
(setq lst2 (cons (polar pt4 ang2 (* dist2 (/ x num))) lst2))
(setq x (+ x 1))
)
(setq lst  (reverse lst ))
(setq lst2 (reverse lst2))

; verts
(setq y 0)
(repeat (length lst)
(command "line" (nth y lst)(nth y lst2) "")
(setq y (+ y 1))
)

; do ends
(setq y 0)
(command "line" pt1 (nth y lst2) "")
(command "line" pt4 (nth y lst) "")

(setq y (- (length lst) 1))
(command "line" pt2 (nth y lst2) "")
(command "line" pt3 (nth y lst) "")

; do mids
(setq y 0)
(repeat (- (length lst) 1)
(command "line" (nth y lst2) (nth (+ y 1) lst) "")
(command "line" (nth y lst) (nth (+ y 1) lst2) "")
(setq y (+ y 1))
)

(setvar 'osmode oldsnap)
(princ)
)
(c:zigzag)
A man who never made a mistake never made anything

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Draw diagonal hatch lines in rectangle by pick
« Reply #36 on: April 17, 2021, 07:10:03 PM »
I was impressed by your stair DCL just 1 question does it check the rise/run rules for stairs ?

This is plain Autocad developed 1990's still available very cheap PM me.

A man who never made a mistake never made anything

Christina

  • Newt
  • Posts: 27
Re: Draw diagonal hatch lines in rectangle by pick
« Reply #37 on: April 18, 2021, 07:07:31 AM »
Quote
It would be a great idea to consider a few fees

Hello Tharwat,
Just a rational thought...
Many employees come to a forum asking for code to impress their boss.
As a result, they can get their job done faster and the boss benefits more... and all looks very happy.   :laugh:
It is therefore easily (for me) understandable that you ask them for a fees.
But can we applies this to a student who is still at school?  :thinking:
Of course you never know who ask for help...

Anyway, thank you for your offer, I'll think about how I can get money.
And thank you very much for your hard work!

Christina


Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: Draw diagonal hatch lines in rectangle by pick
« Reply #38 on: April 18, 2021, 07:37:26 AM »
Hi,
My second version of the program provided works for me in all circumstances and I already recorded a quick demo showing that the program also works on the drawing you attached where the program failed for you.

The program is somehow simple and straight forward the aim that it was wrote for, so how can I modify it for you since it is working properly all the time for me?

Are you adding any codes or adding my codes to another program ?

Christina

  • Newt
  • Posts: 27
Re: Draw diagonal hatch lines in rectangle by pick
« Reply #39 on: April 18, 2021, 09:26:21 AM »
Hello Bigal,

Quote
Would appreciate if you could try it

Thank you very much for your code it works with all my tests so also Test63!
But sadly the zigzags are on the short and not on the long side.
And 1 zigzag/segment  is not possible...

Quote
just 1 question does it check the rise/run rules for stairs ?
First there is a difference between DCL and OpenDCL...
Yes, i use the formula step-modulus (from my country) and everything is automatic.
When I lower or increase the 15 steps, I see when the staircase is optimal. In the photo, 63.06 cm is bit too high and will be showing in the color red; 15 steps are in this example not 100 % optimal... but still OK of course.
I write the stair data and colors also to a ini file as defaults.
You can see the results in the image but its still work in progress...

Quote
This is plain Autocad developed 1990's still available very cheap PM me.

Very nice but I don't use AutoCad for 3D work, the renders aren't realistic enough for me.
I consider myself more has a 3D artist?
Thank you for all

Christina



Christina

  • Newt
  • Posts: 27
Re: Draw diagonal hatch lines in rectangle by pick
« Reply #40 on: April 18, 2021, 09:56:57 AM »
Hello Tharwat,

Quote
My second version of the program provided works for me in all circumstances and I already recorded a quick demo showing that the program also works on the drawing you attached where the program failed for you.

Yes, you really did your best and admire you a lot!  :smitten:
Solving a problem that pops up now and then and works for some people and not are a deadly challenge...
Bigal's code works in TEST63 and TEST45 but does not take a long side and 1 segment.
So, my logic tells me that the fault lies with me and need to reinstall my Windows and AutoCad because the problem will also continue with fees. If there are still problems afterwards, my mom will borrow me little money and will contact you.
Thank you again for what you did!

Christina

Edit: For all the tests i use your original code!


« Last Edit: April 18, 2021, 10:05:21 AM by Christina »

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: Draw diagonal hatch lines in rectangle by pick
« Reply #41 on: April 18, 2021, 11:03:37 AM »
Solving a problem that pops up now and then and works for some people and not are a deadly challenge...
Just wondering whom these people are?

So, my logic tells me that the fault lies with me and need to reinstall my Windows and AutoCad because the problem will also continue with fees.
I believe the problem has nothing to do with Windows nor AutoCAD.
my mom will borrow me little money and will contact you.
Please do not, I don't like to feel guilty against anyone, so I will never accept that.

Have a good weekend.

Christina

  • Newt
  • Posts: 27
Re: Draw diagonal hatch lines in rectangle by pick
« Reply #42 on: April 18, 2021, 12:40:50 PM »
Quote
Just wondering whom these people are?

Hello Tharwat,
A good example now is AutoCad 2022!
Some people have problems with slow mouse movement and some not!
I needed to enter GFXDX12 into the command line and set that to 0 to switch from DirectX 12 to 11.

Quote
I believe the problem has nothing to do with Windows nor AutoCAD.
I believe you, but I work in steps and will be sure that Win + Acad are no longer my problem.

Yes, have a good weekend Tharzat
Christina



Christina

  • Newt
  • Posts: 27
Re: Draw diagonal hatch lines in rectangle by pick
« Reply #43 on: April 21, 2021, 07:45:14 PM »
Hello Tharwat,

I reinstalled Windows and AutoCAD and the errors keep coming ... so you were right.
Studied all the code I received and mixed it together to form the bulletproof cocktail for my computer.
The code is not 100% correct and is not elegant but does what it should do.

Thank you all for the hard work!  :smitten:

Christina


Code - Auto/Visual Lisp: [Select]
  1. (defun c:Kasten ( / *error* *aantal* oldsnap oldlayer old tmp pt pt1 pt2 pt3 pt4 ang1 ang2 ang3 ang4 dist1 dist2 dist3 dist4 lst1 lst2 x y )
  2.         (defun *error*(msg)
  3.                 (setq *error* nil)
  4.                 (princ)
  5.         )
  6.         (if (not (and (tblsearch "layer" "KASTEN")(tblsearch "ltype" "DASHED2")))
  7.                 (progn
  8.                         (setq oldlayer (getvar "CLAYER")) ;get the current first
  9.                         (alert "No Kasten layer and or DASHED2, will be created.")
  10.                         (command "_.Layer" "_make" "KASTEN" "_ltype" "DASHED2" "6" "")
  11.                 )
  12.         )
  13.  
  14.         (setq oldsnap (getvar 'osmode))                                                
  15.         ;(setvar 'osmode 0)                                                                    
  16.         (setq old (entlast))
  17.         (setq pt (getpoint "\nPick point inside rectang "))    
  18.         (command "bpoly" pt "")                                        
  19.         (setq co_ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (entlast)))))
  20.        
  21.         (or (not (equal old (setq new (entlast))))
  22.                 (command "_.regen")
  23.                 (alert "Invalid point. Try again")  
  24.                 (exit)
  25.         )
  26.        
  27.         (progn
  28.                 (foreach itm (entget new)
  29.                         (and (= (car itm) 10) (setq lst1 (cons (cdr itm) lst1)))
  30.                 )
  31.                 lst1
  32.         )
  33.         (or (and (= 4 (length lst1))
  34.                 (setq lst1 (vl-sort lst1 '(lambda (j k) (< (car j) (car k)))))
  35.                         (mapcar 'set '(pt1 pt2 pt3 pt4) lst1)
  36.                         (equal (distance pt1 pt3) (distance pt2 pt4) 1e-4)
  37.                         (or (> (distance pt1 pt3) (distance pt1 pt2))
  38.                                 (setq tmp pt2
  39.                                         pt2 pt3
  40.                                         pt3 tmp
  41.                                 )
  42.                         )
  43.                         (or (> (cadr pt2) (cadr pt1))
  44.                                 (setq tmp pt1
  45.                                         pt1 pt2
  46.                                         pt2 tmp
  47.                                 )
  48.                         )
  49.                         (or (> (cadr pt4) (cadr pt3))
  50.                                 (setq tmp pt3
  51.                                         pt3 pt4
  52.                                         pt4 tmp)
  53.                         )
  54.                 )
  55.                 (and (entdel new)
  56.                         (progn
  57.                                 (alert "Invalid polyline has not 4 corners!")
  58.                                 (exit)
  59.                         )
  60.                 )
  61.         )
  62.        
  63.        
  64.         ;(command "erase" (entlast) "")
  65.         (entdel new)                                   
  66.        
  67.         (setq
  68.                 pt1 (nth 0 co_ord)                             
  69.                 pt2 (nth 1 co_ord)                             
  70.                 pt3 (nth 2 co_ord)                             
  71.                 pt4 (nth 3 co_ord)                             
  72.                
  73.                 ang1 (angle pt4 pt1)           
  74.                 ang2 (angle pt3 pt2)           
  75.                 dist1 (distance pt1 pt4)       
  76.                 dist2 (distance pt2 pt3)       
  77.                
  78.                 ang3 (angle pt1 pt2)           
  79.                 ang4 (angle pt4 pt3)           
  80.                 dist3 (distance pt1 pt2)       
  81.                 dist4 (distance pt4 pt3)               
  82.         )
  83.        
  84.         (If (> dist1 dist3)    
  85.                 (progn                                                 
  86.                         ;(princ "Vertical")
  87.                         (princ "\n 1 = ")(princ (/ (distance pt1 pt4) 1))       ;      2 _ dist3_ 1
  88.                         (princ "\n 2 = ")(princ (/ (distance pt1 pt4) 2))       ;          |        |
  89.                         (princ "\n 3 = ")(princ (/ (distance pt1 pt4) 3))       ;          |        |
  90.                         (princ "\n 4 = ")(princ (/ (distance pt1 pt4) 4))       ;          |        |
  91.                         (princ "\n 5 = ")(princ (/ (distance pt1 pt4) 5))       ; dist2|        |dist1
  92.                         (princ "\n 6 = ")(princ (/ (distance pt1 pt4) 6))       ;          |        |
  93.                         (princ "\n 7 = ")(princ (/ (distance pt1 pt4) 7))       ;          |        |
  94.                         (princ "\n 8 = ")(princ (/ (distance pt1 pt4) 8))       ;          |        |
  95.                         (princ "\n 9 = ")(princ (/ (distance pt1 pt4) 9))       ;           --------
  96.                         (princ)                                                                 ;      3   dist4  4
  97.                 )
  98.                 (progn                                                 
  99.                         ;(princ "Horizontal")
  100.                         (princ "\n 1 = ")(princ (/ (distance pt1 pt2) 1))       ;      2 __dist3__ 1
  101.                         (princ "\n 2 = ")(princ (/ (distance pt1 pt2) 2))       ;         |                |
  102.                         (princ "\n 3 = ")(princ (/ (distance pt1 pt2) 3))       ; dist2|                |dist1
  103.                         (princ "\n 4 = ")(princ (/ (distance pt1 pt2) 4))       ;         |                |
  104.                         (princ "\n 5 = ")(princ (/ (distance pt1 pt2) 5))       ;         ---------------
  105.                         (princ "\n 6 = ")(princ (/ (distance pt1 pt2) 6))       ;         3   dist4    4
  106.                         (princ "\n 7 = ")(princ (/ (distance pt1 pt2) 7))       ;          
  107.                         (princ "\n 8 = ")(princ (/ (distance pt1 pt2) 8))       ;          
  108.                         (princ "\n 9 = ")(princ (/ (distance pt1 pt2) 9))       ;
  109.                         (princ)
  110.                 )
  111.         )
  112.                
  113.         (or *aantal* (setq *aantal* 1))
  114.         (or (initget 6)
  115.                 (setq *aantal* (cond ((getint (strcat "\nAantal indelingen < " (itoa *aantal*) " > : "))) (*aantal*)))
  116.         )
  117.         (setq lst1 '())
  118.         (setq lst2 '())
  119.         (setq x 1.0)
  120.        
  121.         (If (= *aantal* 1)
  122.                 (progn
  123.                         (setq lst1 (cons (polar pt4 ang1 (* dist1 (/ x *aantal*))) lst1))
  124.                         (setq lst2 (cons (polar pt3 ang2 (* dist2 (/ x *aantal*))) lst2))
  125.                         (setq y (- (length lst1) 1))
  126.                         (line_  pt4 (nth y lst2))
  127.                         (line_  pt3 (nth y lst1))
  128.                 )
  129.                 (progn
  130.                         (If (> dist1 dist3)
  131.                                 (progn
  132.                                         (repeat (- (fix *aantal*) 1)   
  133.                                                 (setq lst1 (cons (polar pt4 ang1 (* dist1 (/ x *aantal*))) lst1))
  134.                                                 (setq lst2 (cons (polar pt3 ang2 (* dist2 (/ x *aantal*))) lst2))
  135.                                                 (setq x (+ x 1))
  136.                                         )
  137.                                         (setq y 0)
  138.                                         (repeat (length lst1)
  139.                                                 (line_ (nth y lst1)(nth y lst2))
  140.                                                 (setq y (+ y 1))
  141.                                         )
  142.                                         (setq y 0)
  143.                                         (line_  pt1 (nth y lst2))
  144.                                         (line_  pt2 (nth y lst1))
  145.                                         (setq y (- (length lst1) 1))
  146.                                         (line_  pt4 (nth y lst2))
  147.                                         (line_  pt3 (nth y lst1))
  148.                                         (setq y 0)
  149.                                         (repeat (- (length lst1) 1)
  150.                                                 (line_ (nth y lst2) (nth (+ y 1) lst1))
  151.                                                 (line_ (nth y lst1) (nth (+ y 1) lst2))
  152.                                                 (setq y (+ y 1))
  153.                                         )
  154.                                 )
  155.                                 (progn
  156.                                         (repeat (- (fix *aantal*) 1)
  157.                                                 (setq lst1  (cons (polar pt1 ang3 (* dist3 (/ x *aantal*))) lst1))             
  158.                                                 (setq lst2 (cons (polar pt4 ang4 (* dist4 (/ x *aantal*))) lst2))
  159.                                                 (setq x (+ x 1))
  160.                                         )
  161.                                         (setq y 0)
  162.                                         (repeat (length lst1)
  163.                                                 (line_ (nth y lst1) (nth y lst2))
  164.                                                 (setq y (+ y 1))
  165.                                         )
  166.                                         (setq y 0)
  167.                                         (line_  pt2 (nth y lst2))
  168.                                         (line_  pt3 (nth y lst1))
  169.                                         (setq y (- (length lst1) 1))
  170.                                         (line_  pt1 (nth y lst2))
  171.                                         (line_  pt4 (nth y lst1))
  172.                                         (setq y 0)
  173.                                         (repeat (- (length lst1) 1)
  174.                                                 (line_ (nth y lst2) (nth (+ y 1) lst1))
  175.                                                 (line_ (nth y lst1) (nth (+ y 1) lst2))
  176.                                                 (setq y (+ y 1))
  177.                                         )
  178.                                 )
  179.                         )
  180.                 )
  181.         )
  182.         ;(setvar 'osmode oldsnap)
  183.         (setvar "CLAYER" oldlayer)
  184.         (princ)
  185. )
  186.  
  187.  
  188. (defun line_ (str_ end_)
  189.         (entmakex
  190.                 (list
  191.                         '(0 . "LINE")
  192.                         (cons 10 (trans str_ 1 0))
  193.                         (cons 11 (trans end_ 1 0))
  194.                         (cons 6 "DASHED2")     
  195.                         (cons 62 9)                                            
  196.                         (cons 48 3)                                    
  197.                 )
  198.         )
  199.         (setvar "LTSCALE" 3)                                   
  200. )





BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Draw diagonal hatch lines in rectangle by pick
« Reply #44 on: April 21, 2021, 08:19:00 PM »
Here is my method uses longest side and supports 1 X. Interested to know how it goes in 2022.

Code: [Select]
(defun c:zigzag ( / oldsnap pt pt1 pt2 pt3 pt4 ang1 ang2 dist1 dist2 lst lst2 x y )

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setq pt (getpoint "\nPick point inside rectang "))

(command "bpoly" pt "")
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (entlast)))))
(command "erase" (entlast) "")

(setq pt1 (nth 0 co-ord)
  pt2 (nth 1 co-ord)
  pt3 (nth 2 co-ord)
  pt4 (nth 3 co-ord)
  ang1 (angle pt1 pt2)
  ang2 (angle pt4 pt3)
  dist1 (distance pt1 pt2)
  dist2 (distance pt4 pt3)
)

(if (> dist1 dist2)
(setq co-ord (list (nth 1 co-ord)(nth 2 co-ord)(nth 3 co-ord)(nth 0 co-ord)))
)

(setq num (getreal "\Enter number of segments "))

(if (> num 1)
(progn
(setq lst '())
(setq lst2 '())

(setq x 1.0)
(repeat (- (fix num) 1)
(setq lst  (cons (polar pt1 ang1 (* dist1 (/ x num))) lst))
(setq lst2 (cons (polar pt4 ang2 (* dist2 (/ x num))) lst2))
(setq x (+ x 1))
)
(setq lst  (reverse lst ))
(setq lst2 (reverse lst2))


; do ends
(setq y 0)
(command "line" pt1 (nth y lst2) "")
(command "line" pt4 (nth y lst) "")

(setq y (- (length lst) 1))
(command "line" pt2 (nth y lst2) "")
(command "line" pt3 (nth y lst) "")

; verts
(setq y 0)
(repeat (length lst)
(command "line" (nth y lst)(nth y lst2) "")
(setq y (+ y 1))
)

; do mids
(setq y 0)
(repeat (- (length lst) 1)
(command "line" (nth y lst2) (nth (+ y 1) lst) "")
(command "line" (nth y lst) (nth (+ y 1) lst2) "")
(setq y (+ y 1))
)
)
(progn
(Command "line" (nth 0 co-ord)(nth 2 co-ord) "")
(Command "line" (nth 1 co-ord)(nth 3 co-ord) "")
)
)

(setvar 'osmode oldsnap)
(princ)
)
(c:zigzag)

A man who never made a mistake never made anything