Author Topic: Need help adding a Z value to the Lisp  (Read 3020 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2598
  • I can't remeber what I already asked! I need help!
Need help adding a Z value to the Lisp
« on: October 19, 2006, 09:11:00 AM »
I have the following lisp which calculates elevations in a block (spot shot block). However, all the blocks are 2d with 0.0 elevation to them. I would Like to know if they can be set to the elevation of the block to a Z value being the same as the block.

Code: [Select]
(defun c:sltag ( / scft nstelev nslope FIRSTPT PT1 PT2 distm dist1 nxtelev)
 
;Set defaults on first use
 
(if (= stelev nil)  (setq stelev 800.00))
(if (= slope nil)   (setq slope -0.02))
 
(command ".undo" "begin")
(setvar "cmdecho" 0)
(setvar "attdia" 0)
(setvar "texteval" 1)
(setq scft (getvar "LTscale"))
 (if (= 2 (getvar "lunits")) (setq tunit 2 tprec 3) )
 (if (= 4 (getvar "lunits")) (setq tunit 4 tprec 4) )
   (if (setq nstelev (getdist (strcat "Enter Starting Elevation <" (RTOS stelev) ">: ")))
       (setq stelev nstelev)
   )
   (if (setq nslope (getreal (strcat "Enter Slope Factor (Negative For Down) <" (RTOS slope 2 8) ">: ")))
       (setq slope nslope)
   )
  (setq FIRSTPT (getpoint "Select Starting point ")
   PT2 (getpoint FIRSTPT "\nNext point ")
   distm (distance firstpt pt2)
   nxtelev (+ (* distm slope) stelev)
  )
(princ (strcat "\n                        Distance is  " (rtos (distance firstpt pt2))))
(princ (strcat "\n                           Slope is  " (rtos (* distm slope))))
(princ (strcat "\n                       Elevation is  " (rtos nxtelev tunit tprec)))
;;;; (txstla)

(command "-insert" "E:/CAD/Ielev" "s" scft "r" "0" pt2 (strcat (rtos nxtelev 2 2)""))
  (while (/= PT2 nil)
    (setq PT1 PT2)
    (setq PT2 (getpoint PT1 "\n\nNext point "))
    (if (/= PT2 nil)
      (progn
   (setq dist1 (distance pt1 pt2)
         distm (+ distm dist1)
         nxtelev (+ (* dist1 slope) nxtelev)
   )
   (princ (strcat "\n                        Distance is  " (rtos dist1)))
   (princ (strcat "\n                           Slope is  " (rtos (* dist1 slope))))
   (princ (strcat "\n                       Elevation is  " (rtos nxtelev tunit tprec)))
   (princ (strcat "\n          Running Total Distance is  " (rtos distm)))
 
(command "-insert" "E:/CAD/Ielev" "s" scft "r" "0" pt2 (strcat (rtos nxtelev 2 2)""))
      )
    )
  )
   (princ (strcat "\n\n          Final Total Distance is  " (rtos distm)))
(setvar "attdia" 1)
(command ".undo" "end")
(princ)
)


thanks


<edit: code tags added>
« Last Edit: October 19, 2006, 09:15:43 AM by CAB »
Civil3D 2020

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Need help adding a Z value to the Lisp
« Reply #1 on: October 19, 2006, 09:30:17 AM »
Not sure of your question.
Looks like the block is being inserted at the matching Z.
Are you having trouble setting an attribute to the Z value?
Could you post a DWG with the block?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Need help adding a Z value to the Lisp
« Reply #2 on: October 19, 2006, 10:49:41 AM »
When you use the command to insert a block with attributes you must address the following system variables.

Quote
ATTDIA
Controls whether the -INSERT command uses a dialog box for attribute value entry. See "INSERT Command Line."
0   Issues prompts on the command line
1   Uses a dialog box

ATTMODE
Controls display of attributes.
0   Off: Makes all attributes invisible
1   Normal: Retains current visibility of each attribute: visible attributes are
                displayed; invisible attributes are not
2   On: Makes all attributes visible

ATTREQ
Determines whether the INSERT command uses default attribute settings during insertion of blocks.
0   Assumes the defaults for the values of all attributes
1   Turns on prompts or dialog box for attribute values, as specified by ATTDIA

TEXTEVAL
Controls the method of evaluation of text strings.
0   All responses to prompts for text strings and attribute values are taken literally
1   Text starting with an opening parenthesis [ ( ] or an exclamation mark (!) is
      evaluated as an AutoLISP expression, as for nontextual input


Code: [Select]
(setq sysattdia (getvar "ATTDIA"))
(setq sysattreq (getvar "ATTREQ"))
(setq systxteva (getvar "TEXTEVAL"))
(setvar "ATTDIA" 0)
(setvar "ATTREQ" 1)
(setvar "TEXTEVAL" 0)


<do your lisp>


(setvar "ATTDIA"   sysattdia)
(setvar "ATTREQ"   sysattreq)
(setvar "TEXTEVAL" systxteva)

<code not tested>
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MSTG007

  • Gator
  • Posts: 2598
  • I can't remeber what I already asked! I need help!
Re: Need help adding a Z value to the Lisp
« Reply #3 on: October 20, 2006, 04:30:39 PM »
Cab
Here are the spots in the dwg, please let me know what you think!

Thanks!!
Civil3D 2020

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Need help adding a Z value to the Lisp
« Reply #4 on: October 20, 2006, 05:35:51 PM »
Maybe this?

Code: [Select]
(defun c:sltag (/ bname distm nslope nstelev nxtelev pt1 pt2 scft
                slope stelev sysattdia sysattreq systxteva tprec tunit)

  ;; Set defaults on first use
  (or stelev (setq stelev 800.00))
  (or slope (setq slope -0.02))

  (command ".undo" "begin")
  (setvar "cmdecho" 0)
  (setq sysattdia (getvar "ATTDIA"))
  (setq sysattreq (getvar "ATTREQ"))
  (setq systxteva (getvar "TEXTEVAL"))
  (setvar "ATTDIA" 0)
  (setvar "ATTREQ" 1)
  (setvar "TEXTEVAL" 0)

  (setq scft (getvar "LTscale"))
  (cond
    ((= 2 (getvar "lunits"))
     (setq tunit 2
           tprec 3))
    ((= 4 (getvar "lunits"))
     (setq tunit 4
           tprec 4))
  )

  (if (setq nstelev
             (getdist (strcat "Enter Starting Elevation <"
                              (rtos stelev) ">: ")))
    (setq stelev nstelev)
  )

  (if (setq nslope (getreal (strcat "Enter Slope Factor (Negative For Down) <"
                                    (rtos slope 2 8) ">: ")))
    (setq slope nslope)
  )

  (setq bname "Ielev")
  (if
    (cond
      ;; block already in DWG
      ((tblsearch "block" "Ielev"))
      ((findfile "E:/CAD/Ielev.dwg")
       (command "-insert" bname ^C) ; add the block definition
      )
      ((alert "ERROR: Could not locate block - Ielev"))
    )
     (if (setq pt1 (getpoint "Select Starting point "))
       (while (setq pt2 (getpoint pt1 "\nNext point "))

         (setq distm   (distance pt1 pt2)
               nxtelev (+ (* distm slope) stelev)
         )
         (princ (strcat "\n                        Distance is  "
                        (rtos (distance pt1 pt2))))
         (princ (strcat "\n                           Slope is  "
                   (rtos (* distm slope))))
         (princ (strcat "\n                       Elevation is  "
                        (rtos nxtelev tunit tprec)))
         (princ (strcat "\n          Running Total Distance is  "
                        (rtos distm)))
        ;; (txstla)
         (setq pt2 (list (car pt2) (cadr pt2) distm)) ; adjust Z for block
         (command "-insert" bname "s" scft "r" "0" pt2
                  (strcat (rtos nxtelev 2 2) "")
         )
         (setq pt1 pt2)
       )
       (princ (strcat "\n\n          Final Total Distance is  " (rtos distm)))
     )
  )

  (setvar "ATTDIA" sysattdia)
  (setvar "ATTREQ" sysattreq)
  (setvar "TEXTEVAL" systxteva)
  (command ".undo" "end")
  (princ)
)
« Last Edit: October 20, 2006, 05:42:54 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.