Jump to content

Draw cable tray T connection


mostafa badran

Recommended Posts

Hi,all

I need help to create lisp to draw T connection in cable tray Sys.

I need to ask user as below

Enter T connection type Radius / Chamfered ?

if chosen radius

Enter radius size:

if chosen chamfer

Enter chamfer length:

for booth radius, chamfer Enter width

Enter T connection width:

for more clarity see attached Sample.dwg file.

any help appreciated

thanks for all

M Badran

Link to comment
Share on other sites

  • Replies 25
  • Created
  • Last Reply

Top Posters In This Topic

  • BIGAL

    8

  • ronjonp

    6

  • Tharwat

    4

  • mostafa badran

    4

Top Posters In This Topic

Posted Images

Why not just create 2 dynamic blocks ? No code needed.

 

If you want a lisp answer its a pretty simple shape just use "polar" to work out the points. I would use a DCL for the input with a Button for the Radius or Chamfer question.

Screen Shot 08-02-17 at 03.07 PM.PNG

Link to comment
Share on other sites

If you want a lisp answer its a pretty simple shape just use "polar" to work out the points. I would use a DCL for the input with a Button for the Radius or Chamfer question.

 

Hi BIGAL,

 

I am eager to see how simple that is ! Have you written any codes for this task?

Link to comment
Share on other sites

I am a little busy at moment have limited spare time, but will try to find some time. Will do dynamic block 1st as its something I don't do often.

 

I don't think Dynamic Block would help in this case as long as the input values are varies and what's more bothers that Tee with two curved angles.

 

I did ask you about the codes that you have said that it is really simple to write.

Link to comment
Share on other sites

Please note I am using the sample dwg as my guide as I dont do cable trays. Here is 3rd go. I do appreciate that I have probably used the wrong start point but that can be adressed. Same as trays on an angle could be added also.

 

I will do the front end dcl last.

 

; by Alan H Aug 2017 
; very simple cable routine only uses 1 width but dialog has two so code can be changed easily

(defun cabtrayinput ( / )
(setq dcl_id (load_dialog  "C:\\acadtemp\\cabtray.dcl")) ; change directory to user directory
(if (not (new_dialog "ddcabtray" dcl_id))
(exit))
(mode_tile "key1" 3)
(set_tile "key1" (setq val1 "200"))
(action_tile "key1" "(setq val1 $value)")
(mode_tile "key2" 3)
(set_tile "key2" (setq val2 "200"))
(action_tile "key2" "(setq val2 $value)")
(mode_tile "key3" 3)
(set_tile "key3" (setq val3 "75"))
(action_tile "key3" "(setq val3 $value)")
(start_dialog)
(done_dialog)
(unload_dialog dcl_id)
)

(defun c:ctray ( / pt1 pt2 pt3 pt4 pt5 pt6 w rad oldsnap oldang)
(setq oldsnap (getvar "osmode"))
(setq oldang (getvar "angdir"))
(setvar "angdir" 0)
(setq pt1 (getpoint "\nPick lower left corner "))
(setq oldsnap (getvar "osmode"))
(setvar "osmode" 0)
(cabtrayinput)
(setq w (Atof val1))
(setq w2 (Atof val2))
(setq rad (Atof val3))
(setq pt2 (polar pt1 0.0 (+ (* 2.0 rad) w)))
(setq pt3 (polar pt2 (/ pi 2.0) w))
(setq pt4 (polar pt3  (/ pi 2.0) rad))
(setq pt5 (polar pt4 pi (+ w rad)))
(setq pt6 (polar pt5 pi rad))
(command "pLINE"  pt1 "w" 0.0 0.0 pt2 pt3 "arc" pt3 "Ce" pt4 "angle" -90 "L" pt5 "arc" pt5 "Ce" pt6 "angle" -90 "L" "Close" )
(command "-hatch" "S" "last" "" "P" "HEX" 15 0 "")
(setvar "osmode" oldsnap)
(setvar "angdir" oldang)
(princ)
)

(defun c:chtray ( / pt1 pt2 pt3 pt4 pt5 pt6 pt7 pt8 pt9 pt10 w cham oldsnap oldang)
(setq pt1 (getpoint "Pick lower left corner "))
(setq oldsnap (getvar "osmode"))
(setq oldang (getvar "angdir"))
(setvar "angdir" 0)
(setvar "osmode" 0)
(cabtrayinput)
(setq w (Atof val1))
(setq w2 (Atof val2))
(setq cham (Atof val3))
(setq pt2 (polar pt1 (/ pi 2.0) w))
(setq pt3 (polar pt2 0.0 cham))
(setq pt4 (polar pt3  (/ pi 4.0) 150.0 ))
(setq pt5 (polar pt4 (/ pi 2.0) cham))
(setq pt6 (polar pt5 0.0 w))
(setq pt7 (polar pt6 (* pi 1.5) cham))
(setq pt8 (polar pt7 (* pi 1.75) 150.0))
(setq pt9 (polar pt8 0.0 cham))
(setq pt10 (polar pt9  (* pi 1.5) w))
(command "PLINE"  pt1 "w" 0.0 0.0 pt2 pt3 pt4 pt5 pt6 pt7 pt8 pt9 pt10 "Close")
(command "-hatch" "S" "last" "" "P" "HEX" 15 0 "")
(setvar "osmode" oldsnap)
(setvar "angdir" oldang)
(princ)
)

Save this as cabtray.dcl and edit code to where saved.

ddcabtray : dialog {
: column {
: edit_box {
   key = "key1";
label = "Enter tray width 1";
    edit_width = 5;
    edit_limit = 4;
  is_enabled = true ;
   }
spacer_1 ;
: edit_box {
   key = "key2";
label = "Enter tray width 2 ";
    edit_width = 5;
    edit_limit = 4;
  is_enabled = true ;
   }
spacer_1 ;
: edit_box {
   key = "key3";
label = "Offset - Radius";
    edit_width = 5;
    edit_limit = 4;
  is_enabled = true ;
   }
   }
spacer_1 ;
ok_only;}

Edited by BIGAL
Link to comment
Share on other sites

Tharwat look at code above, please note it is written for a novice hence all the variables as points both routines can be reduced to use maybe 3 pt variables. Thats next.

 

Most importantly it matches the original post with limited variable options called for.

Link to comment
Share on other sites

Good one BIGAL and its recommended to localize variables and to add error handling function to avoid error messages and to reset the System variables if any error took a place.

 

I don't think this program needs a dialog otherwise you need to check the values if they are numbers and none nail values before processing to next step of the program.

 

I don't know why did you divide the two designs into two programs!.

 

Have you seen the video that I uploaded in my first post?

 

Have a nice weekend.

Link to comment
Share on other sites

Here's a quick way to make the radius tray ( no error checking on input )

(defun _makeradtray (w h r p)
 (entmake (list '(0 . "LWPOLYLINE")
	 '(100 . "AcDbEntity")
	 '(67 . 0)
	 '(8 . "E-PWER-CABL-TRAY")
	 '(100 . "AcDbPolyline")
	 '(90 . 
	 '(70 . 1)
	 '(43 . 0)
	 '(38 . 0)
	 '(39 . 0)
	 (cons 10 p)
	 (cons 10 (setq p (list (+ w (car p)) (cadr p))))
	 '(42 . 0.414213562373095)
	 (cons 10 (setq p (list (+ r (car p)) (- (cadr p) r))))
	 (cons 10 (setq p (list (car p) (- (cadr p) h))))
	 (cons 10 (setq p (list (- (car p) (+ w (* 2. r))) (cadr p))))
	 (cons 10 (setq p (list (car p) (+ (cadr p) h))))
	 '(42 . 0.414213562373095)
	 (cons 10 (setq p (list (+ r (car p)) (+ (cadr p) r))))
   )
 )
)
(_makeradtray
 (getdist "\nEnter Width: ")
 (getdist "\nEnter Height: ")
 (getdist "\nEnter Radius: ")
 (getpoint "\nPick a point to place the tray: ")
)

Link to comment
Share on other sites

Code could be tidied up a bit but seems to work well for the two examples in your drawing.

(defun c:trays (/ _getdist _makeradtray _makechamtray p)
 ;; RJP - 08.08.2017
 (defun _makeradtray (w h r p)
   (entmake (list '(0 . "LWPOLYLINE")
	   '(100 . "AcDbEntity")
	   '(8 . "E-PWER-CABL-TRAY")
	   '(100 . "AcDbPolyline")
	   '(90 . 7)
	   '(70 . 1)
	   (cons 10 p)
	   (cons 10 (setq p (list (+ w (car p)) (cadr p))))
	   '(42 . 0.414213562373095)
	   (cons 10 (setq p (list (+ r (car p)) (- (cadr p) r))))
	   (cons 10 (setq p (list (car p) (- (cadr p) h))))
	   (cons 10 (setq p (list (- (car p) (+ w (* 2. r))) (cadr p))))
	   (cons 10 (setq p (list (car p) (+ (cadr p) h))))
	   '(42 . 0.414213562373095)
	   (cons 10 (setq p (list (+ r (car p)) (+ (cadr p) r))))
     )
   )
 )
 (defun _makechamtray (w h c p / sp)
   (setq sp p)
   (entmake (list '(0 . "LWPOLYLINE")
	   '(100 . "AcDbEntity")
	   '(8 . "E-PWER-CABL-TRAY")
	   '(100 . "AcDbPolyline")
	   '(90 . 10)
	   '(70 . 1)
	   (cons 10 p)
	   (cons 10 (setq p (list (+ c (car p)) (cadr p))))
	   (cons 10 (setq p (polar p (angtof "45") (* c 2))))
	   (cons 10 (setq p (list (car p) (+ c (cadr p)))))
	   (cons 10 (setq p (list (+ w (car p)) (cadr p))))
	   (cons 10 (setq p (list (car p) (- (cadr p) c))))
	   (cons 10 (setq p (polar p (angtof "315") (* c 2))))
	   (cons 10 (setq p (list (+ c (car p)) (cadr p))))
	   (cons 10 (setq p (list (car p) (- (cadr p) h))))
	   (cons 10 (setq p (list (- (car p) (- (car p) (car sp))) (cadr p))))
	   (cons 10 (setq p (list (car p) (+ (cadr p) h))))
     )
   )
 )
 (defun _getdist (msg default)
   (cond ((getdist (strcat "\n" msg ": <" (vl-princ-to-string default) ">: ")))
  (default)
   )
 )
 ;; Global defaults
 (or *trayswidth* (setq *trayswidth* 200))
 (or *traysheight* (setq *traysheight* 200))
 (or *trayschamfer* (setq *trayschamfer* 75))
 (or *traysradius* (setq *traysradius* 100))
 (or *traysdefault* (setq *traysdefault* "Radius"))
 (initget 0 "Chamfer Radius")
 (setq	*traysdefault*
 (cond
   ((getkword (strcat "\nPick tray type[Chamfer/Radius]: <" *traysdefault* ">: "))
   )
   (*traysdefault*)
 )
 )
 (setq *trayswidth* (_getdist "Enter Width" *trayswidth*))
 (setq *traysheight* (_getdist "Enter Height" *traysheight*))
 (if (= *traysdefault* "Radius")
   (setq *traysradius* (_getdist "Enter Radius" *traysradius*))
   (setq *trayschamfer* (_getdist "Enter Chamfer" *trayschamfer*))
 )
 (if (setq p (getpoint "\nPick a point to place the tray: "))
   (if	(= *traysdefault* "Radius")
     (_makeradtray *trayswidth* *traysheight* *traysradius* p)
     (_makechamtray *trayswidth* *traysheight* *trayschamfer* p)
   )
 )
 (princ)
)

Link to comment
Share on other sites

ronjonp you are right I could have done the plines just using the (setq pt (polar pt ang dist)) for each new pt 1 after each other, I tried to show for a beginner how to work out a sequence of points. Also in the example I posted I need to add a setvar to ensure I am working in decimal degrees for the -90.

 

I do have a question I know what the 42 code is "bulge" but I am a little confused how it matches 90 degrees. it apears to be (sqrt 2) -1 which could be construed as 45 degrees to next point.

Link to comment
Share on other sites

Why not just create 2 dynamic blocks ? No code needed.

question.

Sorry for delay, I cant use dynamic blocks because all tray is hatched.

Link to comment
Share on other sites

Code could be tidied up a bit but seems to work well for the two examples in your drawing.

(defun c:trays (/ _getdist _makeradtray _makechamtray p)
 ;; RJP - 08.08.2017
 (defun _makeradtray (w h r p)
   (entmake (list '(0 . "LWPOLYLINE")
          '(100 . "AcDbEntity")
          '(8 . "E-PWER-CABL-TRAY")
          '(100 . "AcDbPolyline")
          '(90 . 7)
          '(70 . 1)
          (cons 10 p)
          (cons 10 (setq p (list (+ w (car p)) (cadr p))))
          '(42 . 0.414213562373095)
          (cons 10 (setq p (list (+ r (car p)) (- (cadr p) r))))
          (cons 10 (setq p (list (car p) (- (cadr p) h))))
          (cons 10 (setq p (list (- (car p) (+ w (* 2. r))) (cadr p))))
          (cons 10 (setq p (list (car p) (+ (cadr p) h))))
          '(42 . 0.414213562373095)
          (cons 10 (setq p (list (+ r (car p)) (+ (cadr p) r))))
        )
   )
 )
 (defun _makechamtray (w h c p / sp)
   (setq sp p)
   (entmake (list '(0 . "LWPOLYLINE")
          '(100 . "AcDbEntity")
          '(8 . "E-PWER-CABL-TRAY")
          '(100 . "AcDbPolyline")
          '(90 . 10)
          '(70 . 1)
          (cons 10 p)
          (cons 10 (setq p (list (+ c (car p)) (cadr p))))
          (cons 10 (setq p (polar p (angtof "45") (* c 2))))
          (cons 10 (setq p (list (car p) (+ c (cadr p)))))
          (cons 10 (setq p (list (+ w (car p)) (cadr p))))
          (cons 10 (setq p (list (car p) (- (cadr p) c))))
          (cons 10 (setq p (polar p (angtof "315") (* c 2))))
          (cons 10 (setq p (list (+ c (car p)) (cadr p))))
          (cons 10 (setq p (list (car p) (- (cadr p) h))))
          (cons 10 (setq p (list (- (car p) (- (car p) (car sp))) (cadr p))))
          (cons 10 (setq p (list (car p) (+ (cadr p) h))))
        )
   )
 )
 (defun _getdist (msg default)
   (cond ((getdist (strcat "\n" msg ": <" (vl-princ-to-string default) ">: ")))
     (default)
   )
 )
 ;; Global defaults
 (or *trayswidth* (setq *trayswidth* 200))
 (or *traysheight* (setq *traysheight* 200))
 (or *trayschamfer* (setq *trayschamfer* 75))
 (or *traysradius* (setq *traysradius* 100))
 (or *traysdefault* (setq *traysdefault* "Radius"))
 (initget 0 "Chamfer Radius")
 (setq    *traysdefault*
    (cond
      ((getkword (strcat "\nPick tray type[Chamfer/Radius]: <" *traysdefault* ">: "))
      )
      (*traysdefault*)
    )
 )
 (setq *trayswidth* (_getdist "Enter Width" *trayswidth*))
 (setq *traysheight* (_getdist "Enter Height" *traysheight*))
 (if (= *traysdefault* "Radius")
   (setq *traysradius* (_getdist "Enter Radius" *traysradius*))
   (setq *trayschamfer* (_getdist "Enter Chamfer" *trayschamfer*))
 )
 (if (setq p (getpoint "\nPick a point to place the tray: "))
   (if    (= *traysdefault* "Radius")
     (_makeradtray *trayswidth* *traysheight* *traysradius* p)
     (_makechamtray *trayswidth* *traysheight* *trayschamfer* p)
   )
 )
 (princ)
)

ronjonp,

Thanks for your help, that gave a help to proceed the radius type, I am already create chamfer type by my humble code.

;m badran
(defun c:tc (/ CHFEX CHFLEN CTW PT1 PT10 PT2 PT3 PT4 PT5 PT6 PT7 PT8 PT9 )
 (defun dtr (a)
   (* pi (/ a 180.0))
 )
 (setq chflen(getdist "\nEnter chamfer length:")
  chfex(/ chflen 2)
  ctw(getdist "\nEnter T connection width::"))
 (setq pt1 (getpoint "\Insert point: ")
  pt2 (polar pt1 (dtr 270.0) ctw)
  pt3 (polar pt2 (dtr 0.0) chfex)
  pt4 (polar pt3 (dtr -45.0)chflen )
  pt5 (polar pt4 (dtr 270.0) chfex)
  pt6 (polar pt5 (dtr 0.0) ctw)
  pt7 (polar pt6 (dtr 90.0) chfex)
  pt8 (polar pt7 (dtr 45.0) chflen)
  pt9 (polar pt8 (dtr 0.0) chfex)
  pt10 (polar pt9 (dtr 90.0) ctw))
 (command "pline" pt1 pt2 pt3 pt4 pt5 pt6 pt7 pt8 pt9 pt10 "c")
 (princ)
)


Link to comment
Share on other sites

...

I do have a question I know what the 42 code is "bulge" but I am a little confused how it matches 90 degrees. it apears to be (sqrt 2) -1 which could be construed as 45 degrees to next point.

 

The 45 degree point (for the right side radius) is calculated by adding the radius to the current X value, then subtracting the radius from the current Y value. Since the point is being redefined as we go in a clockwise direction, it's easy to calculate the next point. :)

(cons 10 (setq p (list (+ r (car p)) (- (cadr p) r))))

Link to comment
Share on other sites

This is my program that I use sometimes but its not a freeware.

This is for the second time that I can't upload a .gif file and that's why I uploaded the video to the following website.

 

http://gph.is/2vkNPoK

Thanks Tharwat for sharing.

Link to comment
Share on other sites

ronjonp,

Thanks for your help, that gave a help to proceed the radius type, I am already create chamfer type by my humble code.

;m badran
(defun c:tc (/ CHFEX CHFLEN CTW PT1 PT10 PT2 PT3 PT4 PT5 PT6 PT7 PT8 PT9 )
 (defun dtr (a)
   (* pi (/ a 180.0))
 )
 (setq chflen(getdist "\nEnter chamfer length:")
  chfex(/ chflen 2)
  ctw(getdist "\nEnter T connection width::"))
 (setq pt1 (getpoint "\Insert point: ")
  pt2 (polar pt1 (dtr 270.0) ctw)
  pt3 (polar pt2 (dtr 0.0) chfex)
  pt4 (polar pt3 (dtr -45.0)chflen )
  pt5 (polar pt4 (dtr 270.0) chfex)
  pt6 (polar pt5 (dtr 0.0) ctw)
  pt7 (polar pt6 (dtr 90.0) chfex)
  pt8 (polar pt7 (dtr 45.0) chflen)
  pt9 (polar pt8 (dtr 0.0) chfex)
  pt10 (polar pt9 (dtr 90.0) ctw))
 (command "pline" pt1 pt2 pt3 pt4 pt5 pt6 pt7 pt8 pt9 pt10 "c")
 (princ)
)


Glad you got it sorted :)

Link to comment
Share on other sites

Mostafa a suggestion it is probably easier to have a little library lisp that does all your angles for the common 90 and 45's. These are global values. Use a (if (not angs)(load "angs")) then last line would be (unloadangs) which sets all globals to nil.

 

I try to work in radians all the time so need a couple of setvars for direction and angle is radians.

 

; angs lisp
(setq a90 (/ pi 2.0)
(setq a270 (* 1.5 pi))
(setq pa (/ pi 4.0))
and so on
(defun unloadangs ()
(setq a90 nil
a270 nil
and so on
)

 

pt2 (polar pt1 (dtr 270.0) ctw)
now
pt2 (polar pt1 a270 ctw)

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