Jump to content

Replacing Dimension text with variables in a function


Kwik Drafting

Recommended Posts

I need to replace the actual dimension text so  that it would look like this ----4 spa @ 5'-0 = 20'-0,

where the "4" is replaced by the variable "qty",

the "spa @" is always there,

the "5'-0" is replaced with the variable "off",

and the "20'-0" is given as the default - <>.

 

Any Ideas?

TESTING Equal Beam Spacing.lsp

Link to comment
Share on other sites

A couple of things when you draw the line then do (setq obj (entlast)) this remembers the line so at end can  "erase" obj 

 

I think you can do the offset simpler using a repeat.


;;;---------------------------------------------------------------------------------------------------------------------;
;;;                 Function C:EB                                                              ;
;;;    Description:    Draws equally spaced Beams in a bay                                ;
;;;                         3/11/19 Dale Poston                                                                         ;
;;;                         3/12/19 changed to "EB" and replaced joists references with beams                ;
;;;            3/14/19 added saving and restoring layer, OSnap, and Dimstyle                                   ;
;;;                added Dimension                                                                         ;
;;;---------------------------------------------------------------------------------------------------------------------;

(defun c:EB ( / p1 p2 p3 d qty off olddim oldsnap oldlayer)

  ;; Save Current Layer                        
  ;; Set Current Layer and Object Snap settings
  (setq oldlayer (getvar "clayer")
  oldsnap (getvar 'osmode)
  olddim (getvar "dimstyle"))
  
    ;(ai_sysvar '(("clayer" . "Beam") ("osmode" . 233)))
    
  (command "_dimstyle" "_r" "kdspacing")
    
  ;;;    get points and number of Beams
(setq p1 (getpoint "\nPick top span point: ")
    p2 (getpoint p1 "\nPick bottom span point: ")
    p3 (getpoint p2 "n\Pick bottom bay far point: ")
    d (distance p2 p3)
    qty (getint "\nHow many spaces: ")
)
     
  ;;;    do the math
  (setq off (/ d qty))        ; Offset amount for Beams (equally spaced)
    
     
  ;;;    draw line from p1 to p2 
  (command "line" p1 p2 "")
  (setq obj (entlast))
  
  
  ;;;    offset for Beams and erase p1 p2
(setvar 'clayer "Beam")
(setq dist 0.0)
(repeat (- qty 1)
(command "offset" (setq dist (+ dist off)) obj p3 "")
)

(command "erase" obj "" )                                              

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;            "Dimension" the Beams                  ;;;
  ;;                Set layer                      ;;;
      (Setvar "clayer" "Dimensions")
     (setq str (strcat (rtos qty 2 0) " spa @ " (rtos off 4 3) " " (rtos d 4 3)))
    (command "dimaligned" p2 p3 "Text" str "@-36,36" )


;; Reset Layer, OS, and Dimstyle
  ;(ai_sysvar nil)
  (setvar "clayer" oldlayer)
  (command "_dimstyle" "_r" olddim)
  (princ)
  )

;;;    End function    

(c:EB)  ;start on load

 

 

Edited by BIGAL
Link to comment
Share on other sites

One of the things that came obvious to me was that by asking how many, your spacing could be to big and not meet code, it may be better to ask for max spacing and it can be applied.

 

A bit of a short cut if your happy to type say (EB 1.25) at the command line implies run eb with a spacing of 1.25 or 1' 3". Its 50/50 to ask for input when running.

Link to comment
Share on other sites

BIGAL,

Thanks!!

that works great and is much simpler...I just started trying to do code autolisp 8 weeks ago - in between projects.

There are additional Items I need to add to this function....hopefully I can build on what you have shown.

I'm very grateful for your help.

Link to comment
Share on other sites

Happy to help out just ask what is next, me and others can provide guidance on how to do stuff and you can have a go at it, we will help fix it when it does not work.

 

Its better to see someone having a go rather than continually asking for stuff like some one else who has just posted. Has 629 posts should have learnt by now.

Link to comment
Share on other sites

Well, here is where I am....

I think I've messed some of it up....

I'm trying to add 2 scenarios  - one if I need to label the beams separately and one if I can label all of them.

Some of my layers are not getting set now....

I've include the lisp as a file attachment and the "label" .dwg

 

If you or anyone can help - it is much appreciated.

 

;;;---------------------------------------------------------------------------------------------------------------------;
;;;                 Function C:EB                                                                                       ;
;;;    Description:    Draws equally spaced Beams in a bay                                                ;
;;;                         3/11/19 Dale Poston                                                                         ;
;;;                         3/12/19 changed to "EB" and replaced joists references with beams                        ;
;;;            3/14/19 added saving and restoring layer, OSnap, and Dimstyle                                           ;
;;;                3/17/19 added dimension and simplified by BIGAL                                                         ;
;;;---------------------------------------------------------------------------------------------------------------------;

(defun c:EB ( / p1 p2 p3 d qty off olddim oldsnap oldlayer obj str)

  ;; Save Current Layer                        
  ;; Set Current Layer and Object Snap settings
  (setq oldlayer (getvar "clayer")
      oldsnap (getvar 'osmode)
      olddim (getvar "dimstyle"))    
  (command "_dimstyle" "_r" "kdspacing")
 (ai_sysvar '(("clayer" . "Beam") ("osmode" . 233)))
    
  ;;;    get points and number of Beams
(setq p1 (getpoint "\nPick top span point: ")
       p2 (getpoint p1 "\nPick bottom span point: ")
        p3 (getpoint p2 "n\Pick bottom bay far point: ")
       d (distance p2 p3)
        qty (getint "\nHow many spaces: ")
      ang (angle p1 p2)
)
     
  ;;;    do the math
  (setq off (/ d qty))        ; Offset amount for Beams (equally spaced)
    
     
  ;;;    draw line from p1 to p2 
  (command "line" p1 p2 "")
  (setq obj (entlast))
  
  
  ;;;    offset for Beams and erase p1 p2
(setvar 'clayer "Beam")
(setq dist 0.0)
(repeat (- qty 1)
(command "offset" (setq dist (+ dist off)) obj p3 "")
)

(command "erase" obj "" )


  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;            "Dimension" the Beams                  ;;;
  ;;                Set layer                      ;;;
      (Setvar "clayer" "Dimensions")
     (setq str (strcat (rtos qty 2 0) " spa @ " (rtos off 4 3) " = " (rtos d 4 3)))
    (command "dimaligned" p2 p3 "Text" str "@-36,36" )

 

  ;;;   Insert label:   prompt for single or multi
  ;;;      for single -  insert "label" .dwg and correctly orient
  ;;;    for multi - use dimension line and replace text with label
  
  (setvar "clayer" "beams")
  (command "_dimstyle" "_r" "piecemarks")
  (setq lab (getstring "\nSingle or Multi Label: "))
  (if (= lab single)(command "insert" "label"))
  (if (= lab multi) (command "dimaligned" p2 p3 "text" WX "@-60,60"))
 


;; Reset Layer, OS, and Dimstyle
  (ai_sysvar nil)
  (setvar "clayer" oldlayer)
  (command "_dimstyle" "_r" olddim)
  (princ)
  )

;;;    End function    ;

EJ & EB Model (1).pdf Equal Beam Spacing.lsp

Link to comment
Share on other sites

  • 3 months later...

Bigal,

the routine you helped me with works great!  Thanks!

 

when it displays the "offset" portion of the "str" - it rounds to the nearest 1/8"

Can that be changed to rounding to the nearest 1/16"?

Link to comment
Share on other sites

ok - I think I have it....

Changing the "rtos off 4 3" to "rtos off 4 4" adds a extra decimal point and causes rounding to 16th in.

 

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