Jump to content

HVAC drawings


viviancarvalho

Recommended Posts

I have written this lisp to draw grilles (a/c related) of the desired size with an if condition that if the length specified is smaller than 500mm it will draw one arrow & if more than 500 it will draw 3 arrows.

I am quite sucessful in it also, but there is a small problem. The collar line which is drawn from point c1 to c4 should have the same properties as of the adjacent lines. I even figured out it is happening due to the (setq sa1(entlast) which is coming in the "if". Even all the arrows should be in layer "GRILLE" .I know the reasons for this. but dont know how to solve it.

Can i get some help from the lisp masters. Would also like to know how i can make it more effective.

(jpg attached for ref)

 

;This lisp can draw SAG of desired size & convert it into blocks

(defun c:sg (/ pt1 lth pt2 pt3 pt4 pt5 pt6 pt7 pt8 osm ct c1 c2

c3 c4 ar1 ar2 ar3 ar4 sa1 sa2 sa3 sa4 bd fl t1 t2 t3

t4 t5 t6 t7 t8)

(setvar "cmdecho" 0)

(setq pt1(getpoint "\n Specify the start point : ")

lth(getdist "\n Specify the length of your grille : ")

pt2(polar pt1 1.570796 lth)

pt3(polar pt2 3.141592 75)

pt4(polar pt3 4.712387 lth)

pt5(polar pt1 4.712387 25)

pt6(polar pt5 0.0 25)

pt7(polar pt6 1.570796 (+ lth 50))

pt8(polar pt7 3.141592 25)

osm(getvar "osmode"))

(setvar "osmode" 0)

(command "layer" "n" "GRILLE" "c" "30" "GRILLE" "")

(command "rectangle" pt4 pt2)

(setq bd(entlast))

(command "rectangle" pt5 pt7)

(setq fl(entlast))

(command "change" bd"" "p" "la" "GRILLE" "")

(command "change" fl"" "p" "la" "GRILLE" "")

(setq c1(polar pt1 3.141592 200)

c2(polar pt2 3.141592 300)

c3(polar c2 4.712387 (+ lth 100))

c4(polar c1 1.570796 lth))

(command "line" pt1 c1 c3 "")

(command "line" pt2 c2 "")

(command "line" c1 c4 "")

(setq ar1(polar pt1 1.570796 (/ lth 6))

ar2(polar ar1 1.570796 (/ lth 3))

ar3(polar ar2 1.570796 (/ lth 3))

t1(polar ar1 0.0 250)

t2(polar t1 0.0 150)

t3(polar ar2 0.0 250)

t4(polar t3 0.0 150)

t5(polar ar3 0.0 250)

t6(polar t5 0.0 150)

ar4(polar pt1 1.570796 (/ lth 2))

t7(polar ar4 0.0 250)

t8(polar t7 0.0 150))

(if (

(

(command "pline" ar1 "w" "0" "0" t1 "w" "50" "0" t2"")

(setq sa1(entlast))

(command "pline" ar2 "w" "0" "0" t3 "w" "50" "0" t4"")

(setq sa2(entlast))

(command "pline" ar3 "w" "0" "0" t5 "w" "50" "0" t6"")

(setq sa3(entlast))

(command "change" sa1"" "p" "la" "GRILLE" "")

(command "change" sa2"" "p" "la" "GRILLE" "")

(command "change" sa3"" "p" "la" "GRILLE" "")

)

(

(command "pline" ar4 "w" "0" "0" t7 "w" "50" "0" t8"")

(setq sa4(entlast))

(command "change" sa4"" "p" "la" "GRILLE" "")

))

(setvar "osmode" osm))

grilles-Model.jpg

Link to comment
Share on other sites

  • Replies 39
  • Created
  • Last Reply

Top Posters In This Topic

  • The Buzzard

    24

  • viviancarvalho

    15

  • CarlB

    1

It looks like in your "if" statement you are grouping commands by enclosing in parentheses. Instead you need to use "progn" to group them.

 

So try:

 

(if (< 500 lth)
  (progn
    (command "pline" ar1 "w" "0" "0" t1 "w" "50" "0" t2"")
    (setq sa1(entlast))
    (command "pline" ar2 "w" "0" "0" t3 "w" "50" "0" t4"")
    (setq sa2(entlast))
    (command "pline" ar3 "w" "0" "0" t5 "w" "50" "0" t6"")
    (setq sa3(entlast))
    (command "change" sa1"" "p" "la" "GRILLE" "")
    (command "change" sa2"" "p" "la" "GRILLE" "")
    (command "change" sa3"" "p" "la" "GRILLE" "")
 )
(progn
 (command "pline" ar4 "w" "0" "0" t7 "w" "50" "0" t8"")
 (setq sa4(entlast))
 (command "change" sa4"" "p" "la" "GRILLE" "")
))

 

I can see a few ways you could condense some code, for example change layer of 3 objects:

 

(command "change" sa1 sa2 sa3 "" "p" "la" "GRILLE" "")

Link to comment
Share on other sites

Carl with your help i got my job done previously.Now ve i added something more to the previous lisp. It works fine when u run it for the first time but does not when i use it for the second time with the same value for "lth". The reason being the same block already exists.

What i exactly want is to use the same lisp several times in a dwg with the same block name. If the block already exists then insert the same one again or i dont mind the block being redefined.

 

One more thing is the block name (setq bn) comes out to be "400.0000SAG" when the "lth" is 400 can it be "400 SAG" somehow.

Can you help me again please

 

 

;This lisp can draw SAG of desired size & convert it into blocks

(defun c:sag (/ pt1 lth pt2 pt3 pt4 pt5 pt6 pt7 pt8 osm ct c1 c2

c3 c4 ar1 ar2 ar3 ar4 sa1 sa2 sa3 sa4 bd fl t1 t2 t3

t4 t5 t6 t7 t8)

(setvar "cmdecho" 0)

(setq pt1(getpoint "\n Specify the start point : ")

lth(getdist "\n Specify the length of your grille : ")

pt2(polar pt1 1.570796 lth)

pt3(polar pt2 3.141592 75)

pt4(polar pt3 4.712387 lth)

pt5(polar pt1 4.712387 25)

pt6(polar pt5 0.0 25)

pt7(polar pt6 1.570796 (+ lth 50))

pt8(polar pt7 3.141592 25)

osm(getvar "osmode"))

(setvar "osmode" 0)

(command "layer" "n" "GRILLE" "c" "30" "GRILLE" "")

(command "rectangle" pt4 pt2)

(setq bd(entlast))

(command "rectangle" pt5 pt7)

(setq fl(entlast))

(command "change" bd fl"" "p" "la" "GRILLE" "")

(setq c1(polar pt1 3.141592 200)

c2(polar pt2 3.141592 300)

c3(polar c2 4.712387 (+ lth 100))

c4(polar c1 1.570796 lth))

 

(command "line" pt1 c1 c3 "")

(command "line" pt2 c2 "")

(command "line" c1 c4 "")

(setq ar1(polar pt1 1.570796 (/ lth 6))

ar2(polar ar1 1.570796 (/ lth 3))

ar3(polar ar2 1.570796 (/ lth 3))

t1(polar ar1 0.0 250)

t2(polar t1 0.0 150)

t3(polar ar2 0.0 250)

t4(polar t3 0.0 150)

t5(polar ar3 0.0 250)

t6(polar t5 0.0 150)

ar4(polar pt1 1.570796 (/ lth 2))

t7(polar ar4 0.0 250)

t8(polar t7 0.0 150))

(if (

(progn

(command "pline" ar1 "w" "0" "0" t1 "w" "50" "0" t2"")

(setq sa1(entlast))

(command "pline" ar2 "w" "0" "0" t3 "w" "50" "0" t4"")

(setq sa2(entlast))

(command "pline" ar3 "w" "0" "0" t5 "w" "50" "0" t6"")

(setq sa3(entlast))

(command "change" sa1 sa2 sa3 "" "p" "la" "GRILLE" "")

)

(progn

(command "pline" ar4 "w" "0" "0" t7 "w" "50" "0" t8"")

(setq sa4(entlast))

(command "change" sa4"" "p" "la" "GRILLE" "")

))

(setq bin(polar pt1 1.570796 (/ lth 2)))

(setq bn(strcat (rtos lth) "SAG"))

(if (

(progn (command "select" bd fl sa1 sa2 sa3""))

(progn (command "select" bd fl sa4"")))

(command "block" bn bin "previous" "")

(setvar "osmode" osm)

(command "insert" bn bin "1" "1" "0")

(princ))

Link to comment
Share on other sites

Hey Buzz & Carl i finally got it with the help of you two.

Buzz your first post made it (if (null(tblsearch "block" bn)).

Thanks for that.

Now it does perfectly what i want it to.

Please let me know if i can make it more better.

 

;This lisp can draw SAG of desired size & convert it into blocks

(defun c:sag (/)

(setvar "cmdecho" 0)

(setq pt1(getpoint "\n Specify the start point : ")

lth(getdist "\n Specify the length of your grille : ")

pt2(polar pt1 1.570796 lth)

pt3(polar pt2 3.141592 75)

pt4(polar pt3 4.712387 lth)

pt5(polar pt1 4.712387 25)

pt6(polar pt5 0.0 25)

pt7(polar pt6 1.570796 (+ lth 50))

pt8(polar pt7 3.141592 25)

osm(getvar "osmode"))

(setvar "osmode" 0)

(if (null(tblsearch "layer" "GRILLE"))

(command "layer" "n" "GRILLE" "c" "30" "GRILLE" "")

(princ))

(command "rectangle" pt4 pt2)

(setq bd(entlast))

(command "rectangle" pt5 pt7)

(setq fl(entlast))

(command "change" bd fl"" "p" "la" "GRILLE" "")

(setq c1(polar pt1 3.141592 200)

c2(polar pt2 3.141592 300)

c3(polar c2 4.712387 (+ lth 100))

c4(polar c1 1.570796 lth))

(command "line" pt1 c1 c3 "")

(command "line" pt2 c2 "")

(command "line" c1 c4 "")

(setq ar1(polar pt1 1.570796 (/ lth 6))

ar2(polar ar1 1.570796 (/ lth 3))

ar3(polar ar2 1.570796 (/ lth 3))

t1(polar ar1 0.0 250)

t2(polar t1 0.0 150)

t3(polar ar2 0.0 250)

t4(polar t3 0.0 150)

t5(polar ar3 0.0 250)

t6(polar t5 0.0 150)

ar4(polar pt1 1.570796 (/ lth 2))

t7(polar ar4 0.0 250)

t8(polar t7 0.0 150))

(if (

(progn

(command "pline" ar1 "w" "0" "0" t1 "w" "50" "0" t2"")

(setq sa1(entlast))

(command "pline" ar2 "w" "0" "0" t3 "w" "50" "0" t4"")

(setq sa2(entlast))

(command "pline" ar3 "w" "0" "0" t5 "w" "50" "0" t6"")

(setq sa3(entlast))

(command "change" sa1 sa2 sa3 "" "p" "la" "GRILLE" "")

)

(progn

(command "pline" ar4 "w" "0" "0" t7 "w" "50" "0" t8"")

(setq sa4(entlast))

(command "change" sa4"" "p" "la" "GRILLE" "")

))

(setq bin(polar pt1 1.570796 (/ lth 2)))

(setq bn (strcat (rtos lth 2 0) "SAG"))

(if (

(progn (command "select" bd fl sa1 sa2 sa3""))

(progn (command "select" bd fl sa4"")))

(if (null(tblsearch "block" bn))

(progn(command "block" bn bin "previous" "")

(command "insert" bn bin "1" "1" "0"))

(progn (command "erase" "previous" "")

(command "insert" bn bin "1" "1" "0")))

(setvar "osmode" osm)

(princ))

Link to comment
Share on other sites

Viv,

 

My apologies for deleting my post, But I saw some minor quirks. I am writing this program differently using DXF data to create the block definition from within the program instead. This may also be helpful in way, That if you wish to set your grille on a certain angle, You can get this all done in one session of the program operation.

 

I will most likely post later to give you some kind of idea as to what I mean. I just want to make sure that I post this without any errors.

 

Anyway for now I am glad it works for you. I try to give you a method to make this better.

Link to comment
Share on other sites

Buzz,

I know what you are thinking of. But i need practice to do it that way. Right now what i am thinking of is to align these objects to a line selected by the user. Can you help me in acheiving this. I m also working on the same.

 

Thanks & regards.

Link to comment
Share on other sites

Buzz,

I know what you are thinking of. But i need practice to do it that way. Right now what i am thinking of is to align these objects to a line selected by the user. Can you help me in acheiving this. I m also working on the same.

 

Thanks & regards.

 

 

I am currently setting it up that way now, Also I am going to have the program draw it the way you have the object displayed as well as in a reverse direction for different flow paths.

 

As I also mentioned, I will add a rotation feature to all this and have the program remember the last inputs. This will make the program real keen.

 

I need to study your line coordinates and get familar with the variables used. I am not real quick as some here at the forum so I need to spend a little time on it.

 

I do plan to post it here for your review. I will comment it and let you decide what you would like to use from it. I was also thinking of using a dcl file with it, But for now I will hold off on that as not to get to far ahead myself.

 

Keep an eye open for the program, I am not sure when I will have this done.

Link to comment
Share on other sites

Buzz thats really nice of you. Meanwhile the attachment will clear my line co-ordinates.

I will be waiting for your post.

Drawing hvac-Model.jpg

Link to comment
Share on other sites

Buzz thats really nice of you. Meanwhile the attachment will clear my line co-ordinates.

I will be waiting for your post.

 

Hey Viv!

 

I wish I had those coordinates before, But I never thought to ask.

Anyway I finished this program to give you some sort of ideas for your own program or you may use this one if you wish.

 

You may or maynot like everything I put into this and thats OK. Give this a try and let me know what you think good or bad.

 

This program has the following features:

 

1. Saves the users drafting settings at the beginning of the program and restores them at programs end.

2. Built in error trap, So if you hit escape in mid command, Your settings will be restored.

3. The program has default settings at start-up, So if you just hit enter without entering data, The program will not crash.

4. The program will remember the last data entered during the entire drawing session.

5. I put in a great layer function.

6. You can rotate you block by way of input or dragging the cusor.

7. The program draws the block in two directions of air flow. Left or Right.

8. Puts in three air flow arrows if size is 500 or greater. And single arrow if less than 500.

9. Program has built in block definitions using DXF data created with entmake.

10. Program is fully commented.

 

I know the program may look complex, But it is easier than you think.

I am also sure this program can use some improvement.

I will be glad to answer any questions on it.

 

Type SAG2 to start it.

Enjoy the program.

The Buzzard

SAG2.zip

Link to comment
Share on other sites

Sorry about this Viv,

 

I found out what was wrong, I needed to convert a real to a string a second time in the program. It was all out of sync. This version works the way it is suppose to.

 

 

Here is the corrected change.

  (setq INPT (getpoint "\nSpecify insertion point: "))                      ;Set INPT ~ Insertion Point
 (setq GWID  G:WID)                                                        ;Set GWID  ~ Grille Width   (Real)
 [color=red](setq GWID$ (rtos GWID 2 0))                                              ;Set GWID$ ~ Grille Width[/color]   (String)
 (setq FDIR$ F:DIR$)                                                       ;Set FDIR$ ~ Flow Direction (String)
 (setq FWID (+ GWID 50))                                                   ;Set FWID  ~ Flange Width   (Real)
 (setq BBPT (list 0.0 0.0 0.0))                                            ;Set Block Base Point
 (setq EXDR (list 0.0 0.0 1.0))                                            ;Set Extrusion Direction

 

I also put this back in place.

  (or G:WID    (setq G:WID 500.0))                                          ;Set Grille Width   default to 300,       Remember last setting
 (setq G:WID$ (rtos G:WID 2 0))                                            ;Set Grille Width Value, Return Grille Width to string
 (or F:DIR$   (setq F:DIR$ "R"))                                           ;Set Flow Direction default to R ~ Right, Remember last setting
 (setq G:WID                                                               ;Set Grille width
   (cond                                                                   ;Condition
     ((getreal (strcat "\nSpecify the width of the grille <"G:WID$">: "))) ;Get distance, Show default
     (T G:WID)                                                             ;If Enter is selected, Set to default G:WID ~ Grille Width
   )                                                                       ;End condition
 )                                                                         ;End of setq
 (initget 8 "R L")                                                         ;Establish keyword for Flow Direction R ~ Right or L ~ Left
 (setq F:DIR$                                                              ;Set Flow Direction
   (cond                                                                   ;Condition
     ((getkword (strcat"\nFlow direction? (R or L) <"F:DIR$">: ")))        ;Pause for keyword
     (T F:DIR$)                                                            ;If Enter is selected, Set to default F:DIR ~ Flow Direction
   )                                                                       ;End condition
 )                                                                         ;End of setq

 

 

Attached is the fixed version.

SAG2.zip

Link to comment
Share on other sites

Buzz

Thats just fantastic. Of-course i will be using this one after editing it a bit. But should definitely workout. I liked your code very much its the best.

thanks for your efforts for your line to line explanation. Thats just great.

The best part of it was the degrees to radians conversion in it.

I also tried to make mine a little better than previous.(of-course cant compare with that of yours). I ve also attached an actual use of the same.

If you see mine , i dont want the branch(collar) to be included in the block coz the collar length is always varying.

Anyways i got my direction & will manage with a little bit change in yours. If i dont get it i ll be back to trouble you again.

sag.zip

Link to comment
Share on other sites

Not a problem at all. Glad to help.

 

I am sure you will notice some features that may be of use to you. I covered an awfull lot in this one.

 

Good Luck,

And let me know how its going,

The Buzzard

Link to comment
Share on other sites

Vivian,

 

I am going to take another crack at this program, But I will utilize your method since I now have an idea as to what the variables are. I would like to point out though that I have the air flow direction Left & Right for the reason that you would need to be able to place these Grilles on either side of the duct with respect to Air Flow direction. The rotation feature is only to make the Branchs perpendicular to the main duct. Basically they will look mirrored even though they are not.

 

See attached image.

 

You will also need to put the Save User Settings feature in along with the Restore User Settings.

 

The layer function that I use, Uses the Make sub-command. This will make a new layer if its not in the drawing and set it if it is. I also want to mention that that function will take into account that if a layer in your drawing is frozen, It will then thaw and set it.

 

Finally there is also all your command calls which are not set to be langauge compatable with versions of Acad that come in other langauges.

 

Example:

(command "layer" "n" "GRILLE" "c" "30" "GRILLE" "")     Not langauge compatable.
(command "_.layer" "_n" "GRILLE" "_c" "30" "GRILLE" "") This is langauge compatable.

 

I will also put in the default data settings as well.

 

The code will be alot smaller then the previous one I posted, But will work in the method you would expect. This should bring you much closer to your goal. I will be putting this together over the weekend. I need the practice as well since I have not made any codes in the last few months. I may have it done for early next week.

 

I will contact you then.

Document1.jpg

Link to comment
Share on other sites

Viv,

 

Its your lucky day.

 

Please test out the attached program SAG4.lsp. As I mentioned before, This program is done with all command call as in your program. The only difference is that this has all the neat features of the SAG2.lsp. The block is now on its own layer GRILLE and the duct is on a layer called DUCTING and are line entities. When you get time let me know what you think. By the way, There is a sketch of the objects variables for the grille and duct done in the program to help you follow my variables.

 

This program is your concept, I just arranged it differently.

 

Enjoy!

The Buzzard

SAG4.zip

Link to comment
Share on other sites

Buzz

 

Its definately my lucky day. This is really the best one. Thanks for all your support in making this concept work in a more better way than i had ever thought. I also came to know about many new things from your point to point explanation for each line in the program.

 

Regards

Vivian

Link to comment
Share on other sites

Viv,

 

That's great to know, I do not mind at all when others show a willingness to learn. It seems to me you are willing to put in the time to learn and that is a big reward to me in itself.

 

I realize that the insertion point on that last code was not where you had it, But there was less programming involved to acheive the results from using my own judgement. I hope it works out for you and you continue to show the ability to improve your coding. Of course you can change this to way you deem fit.

 

Again, If you have any questions, Please feel free to ask. I am not one of the better programmers on this site, But I do wish to give back to this site to others who have the willingness to take their codes up a notch.

 

I can only do for this site with the learning I have received, And if this helps you any, Then I have gotton more back then you will ever know. I can only hope that you will return your new found knowledge back here some day to keep this site as special as it is to me.

 

I know sometimes some folks here do not understand this concept, But it is what make some here give back to others for their efforts.

 

One thing I realized was, You would be able to relate to this code because it was your concept from the beginning. It only makes it that much easier for you to take this code to a point that is even better than what I could put out.

 

Good Luck and keep cracking at it,

I learned even more from you than you know.

The Buzzard

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