Jump to content

Recommended Posts

Posted

I want to change the values of a dynamic block within a lisp. This lisp contains a calculation. I used .dcl for this.

 

My dynamic block has 7 attributes: maaiveld, HOOGTE1, HOOGTE2, HOOGTE3, HOOGTE4, HOOGTE5 and HOOGTE6.

 

My lisp code has 7 values: m, a, b, c, x, y and z

 

The order of these outputs are important. a, b, and c are sewer pipes that arrive in the cewer, and x, y, and z are pipes that depart from the sewer pit. So if there are only 2 pipes, we only have to use a and x.

 

This makes it difficult. I can't just set HOOGTE1 to a, HOOGTE2 to b, HOOGTE3 to c, etc. If I do it this way, it will leave a gap in my leader.

 

I hope this is even possible. I provided some screenshots of my calculator and of the leader, and the problem of the gap. Maybe I just need to create a more complex dynamic block, so that I can just connect the hoogte1,2,3,... to a,b,c,... I really don't know.

 

code:

 

(defun c:testKRIS ( / *error* dch dcl des mv d1 d2 d3 d4 d5 d6)
 
    (defun *error* ( msg )
        (if (and (= 'int (type dch)) (< 0 dch))
            (unload_dialog dch)
        )
        (if (= 'file (type des))
            (close des)
        )
        (if (and (= 'str (type dcl)) (findfile dcl))
            (vl-file-delete dcl)
        )
        (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )
 
    (cond
        (   (not
                (setq dcl (vl-filename-mktemp nil nil ".dcl")
                      des (open dcl "w")
                )
            )
            (princ "\nUnable to open DCL for writing.")
        )
        (   (progn
                (foreach str
                   '(
                        "ed : edit_box"
                        "{"
                        "    alignment = left;"
                        "    width = 20;"
                        "    edit_width = 10;"
                        "    fixed_width = true;"
                        "}"
                        ""
                        "test : dialog"
                        "{"
                        "    spacer;"
                        "    key = \"dcl\";"
                        "    : ed"
                        "    {"
                        "        key = \"mv\";"
                        "        label = \"MV:\";"
                        "    }"
                        "    :boxed_column { "
                        "     label = \"Diepte vd buizen\";"
                        "    :row {"
                        "    : ed"
                        "    {"
                        "        key = \"d1\";"
                        "        label = \"A:\";"
                        "    }"
                        "    : ed"
                        "    {"
                        "        key = \"d4\";"
                        "        label = \"X:\";"
                        "    }}"
                        "    :row {"
                        "    : ed"
                        "    {"
                        "        key = \"d2\";"
                        "        label = \"B:\";"
                        "    }"
                        "    : ed"
                        "    {"
                        "        key = \"d5\";"
                        "        label = \"Y:\";"
                        "    }}"
                        "    :row {"
                        "    : ed"
                        "    {"
                        "        key = \"d3\";"
                        "        label = \"C:\";"
                        "    }"                      
                        "    : ed"
                        "    {"
                        "        key = \"d6\";"
                        "        label = \"Z:\";"
                        "    }}"
                        "    }"
                        "    : boxed_row"
                        "    { "
                        "     label = \"BOK berekeningen\";"
                        "    :column {"
                        "        : ed { key = \"res\"; label = \"BOK:\"; is_enabled = false; }"
                        "        : ed { key = \"res2\"; label = \"BOK2:\"; is_enabled = false; }"
                        "        : ed { key = \"res3\"; label = \"BOK3:\"; is_enabled = false; }"
                        "         }"
                        "     :column{"
                        "        : ed { key = \"res4\"; label = \"BOK4:\"; is_enabled = false; }"
                        "        : ed { key = \"res5\"; label = \"BOK5:\"; is_enabled = false; }"
                        "        : ed { key = \"res6\"; label = \"BOK6:\"; is_enabled = false; }"
                        "         }"
                        "    }"
                        "        : button"
                        "        {"
                        "            key = \"cal\";" 
                        "            label = \"Calculate\";"
                        "        }"
                        "    spacer;"
                        "    ok_only;"
                        "}"
                    )
                    (write-line str des)
                )
                (setq des (close des)
                      dch (load_dialog dcl)
                )
                (<= dch 0)
            )
            (princ "\nUnable to load DCL file.")
        )
        (   (not (new_dialog "test" dch))
            (princ "\nUnable to display 'test' dialog.")
        )
        (   t
            (set_tile "dcl" "Calculate Area")
            (action_tile "mv" "(setq mv $value)")
            (action_tile "d1" "(setq d1 $value)")
            (action_tile "d2" "(setq d2 $value)")
            (action_tile "d3" "(setq d3 $value)")
            (action_tile "d4" "(setq d4 $value)")
            (action_tile "d5" "(setq d5 $value)")
            (action_tile "d6" "(setq d6 $value)")
            (action_tile "cal"
                (vl-prin1-to-string
                   '(
                        (lambda ( / m x y z a b c )
                            (set_tile "res" "")
                            (set_tile "res2" "")
                            (set_tile "res3" "")
                            (set_tile "res4" "")
                            (set_tile "res5" "")
                            (set_tile "res6" "")
                            (cond
                                (   (or (not mv) (= "" mv))
                                    (alert "Please enter a maaiveld value.")
                                    (mode_tile "mv" 2)
                                )
                                (   (or (not d1) (= "" d1))
                                    (alert "Please enter a A value.")
                                    (mode_tile "d1" 2)
                                )
                                (   (or (not d2) (= "" d2))
                                    (alert "Please enter a B value.")
                                    (mode_tile "d2" 2)
                                )
                                (   (or (not d3) (= "" d3))
                                    (alert "Please enter a C value.")
                                    (mode_tile "d3" 2)
                                )
                                (   (or (not d4) (= "" d4))
                                    (alert "Please enter a X value.")
                                    (mode_tile "d4" 2)
                                )
                                (   (or (not d5) (= "" d5))
                                    (alert "Please enter a Y value.")
                                    (mode_tile "d5" 2)
                                )
                                (   (or (not d6) (= "" d6))
                                    (alert "Please enter a Z value.")
                                    (mode_tile "d6" 2)
                                )
                              
                                (   (not (setq m (distof mv)))
                                    (alert "Het Maaiveld moet een getal zijn.")
                                    (mode_tile "mv" 2)
                                )
                                (   (not (setq a (distof d1)))
                                    (alert "The A must be numerical.")
                                    (mode_tile "d1" 2)
                                )
                                (   (not (setq b (distof d2)))
                                    (alert "The B must be numerical.")
                                    (mode_tile "d2" 2)
                                )
                                (   (not (setq c (distof d3)))
                                    (alert "Het C moet een getal zijn.")
                                    (mode_tile "d3" 2)
                                )
                                (   (not (setq x (distof d4)))
                                    (alert "The X must be numerical.")
                                    (mode_tile "d4" 2)
                                )
                                (   (not (setq y (distof d5)))
                                    (alert "The Y must be numerical.")
                                    (mode_tile "d5" 2)
                                )
                                (   (not (setq z (distof d6)))
                                    (alert "The Z must be numerical.")
                                    (mode_tile "d6" 2)
                                )
                              
                                (   (<= m 0.0)
                                    (alert "Het maaiveld moet groter dan nul zijn.")
                                    (mode_tile "mv" 2)
                                )
                                (   (<= a 0.0)
                                    (alert "The A must be greater than zero.")
                                    (mode_tile "d1" 2)
                                )
                                (   (<= b 0.0)
                                    (alert "The B must be greater than zero.")
                                    (mode_tile "d2" 2)
                                )
                                (   (<= c 0.0)
                                    (alert "Het C moet groter dan nul zijn.")
                                    (mode_tile "d3" 2)
                                )
                                (   (<= x 0.0)
                                    (alert "The X must be greater than zero.")
                                    (mode_tile "d4" 2)
                                )
                                (   (<= y 0.0)
                                    (alert "The Y must be greater than zero.")
                                    (mode_tile "d5" 2)
                                )
                                (   (<= z 0.0)
                                    (alert "The Z must be greater than zero.")
                                    (mode_tile "d6" 2)
                                )
                                
                                (t
                                    (set_tile "res" (rtos (- m a) 2))
                                    (set_tile "res2" (rtos (- m b) 2))
                                    (set_tile "res3" (rtos (- m c) 2))
                                    (set_tile "res4" (rtos (- m x) 2))
                                    (set_tile "res5" (rtos (- m y) 2))
                                    (set_tile "res6" (rtos (- m z) 2))
                                )
                                    
                                  
                            )
                        
                        )
                    )
                )
            )
          (start_dialog)
        )
    )
    (*error* nil)
    (princ)
)

The code needs work to be visually better, but I want it to work before I do that.

leader a x.png

leader.png

calc and leader.png

Posted

I guess there are good reasons you're not using the pipe network tools in Civil 3D, because you could just define a label style for a structure and be done with it.

 

Here's some simple code for editing attributes inside dynamic blocks. You may have to call the routine three times in a container function, once for each type of variable. For the inverts, I would begin by setting to zero, getting the value, and resetting the variable only if it exists.

 

And as always, Lee Mac did it first: here are some helpful dynamic block functions.

 

My diesel-fu is rusty, does your code do anything besides handle the window and get user input? What are you trying to do that's not possible in the usual attribute editor, besides validating the input?

  • Like 1
Posted

I'am a intern civil designer so I'am using Civil 3D but our surveyors still use Autocad. I was tasked with recreating a leader that is used to display sewer measurements. They normally use there calculator to get the measurements but there where some mistakes in the past.

 

Lee Mac is also the reason that I started to look into Lisp coding. But I'am still new at this. I find it hard to understand every line of my own code but I'am figuring things out on my own pace.

 

My end goal is to put all the outcomes into my dynamic leader. The problem iam having is the order of the 6 possible outcomes. a,b,c and x,y,z. Not all sewer pits are the same. sometimes u have 2 incoming pipes and 1 outgoing so that means the leader only needs A B and X.

but sometimes there is only 1 outgoing pipe so the leader only contains X.

 

If I only have X as outcome It would need to go to the top of the leader in the attribute 'HOOGTE1'

 

if I have A B and X in my calculation:

  • A goes to the top of the leader  =  'HOOGTE1'
  • B goes to under A  =  'HOOGTE2'
  • X goes to the bottom  =  'HOOGTE3'

 

So sometimes X is on top but I'ts also possible that X is on the bottom in 'HOOGTE6' and I dont know if I can create this. 

 

I hope I made some kind of sense. But I think u know my problem. 

 

Schermafbeelding 2024-05-22 155150.png

Posted (edited)

Re blank line if you look at the dcl tile return it will be "". So I use a library Multi getvals.lsp so what it does is makes a list of all the values so if we look at what you have it would be ("11 11" "A22 22" "" "X55" "" "") So you can make a mtext string "11 11\\P22 22\\PX55" when using strcat you check is value "" so skip, get next value.

 

I use a loop to get all tile values in 1 go making a list of the results. Your welcome to look at this code for your 1st dcl, can be used in any code. It has the loop code. You would change MV to say "d0"

 

You can make a list here or further down you have values.

            (action_tile "mv" "(setq mv $value)")
            (action_tile "d1" "(setq d1 $value)")
            (action_tile "d2" "(setq d2 $value)")
            (action_tile "d3" "(setq d3 $value)")
            (action_tile "d4" "(setq d4 $value)")
            (action_tile "d5" "(setq d5 $value)")
            (action_tile "d6" "(setq d6 $value)")

Multi GETVALS.lsp

Edited by BIGAL
Posted

Thanks again BIGAL. I have created a list of the results.  

 

Schermafbeelding2024-05-23100621.png.495b518065569eb595e176430f1a8c7d.png

Schermafbeelding2024-05-23100656.png.ce911e88d20817d9b9ee8b9f251d2116.png

 

Now I need to change the attributes in my dynamic block using that output list. 

Posted

Out of curiosity, why do you need a dynamic block?

Posted

I originally created a dynamic block to replicate a leader. However, I later discoverd that i could simply insert a normal block into a leader. It never occurred to me that i'm no longer using a dynamic block.

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