Results 1 to 5 of 5

Thread: Centerline Part 2

  1. #1
    100 Club
    Join Date
    2005-01
    Posts
    115

    Default Centerline Part 2

    New thread, I took some time to think through this routine. I did not realize all the variables until I had seen some in action

    I have tried to edit a couple of current routines to achieve this, but I am a lisp amatuer

    Is this possible, has anyone seen a routine like this

    Pick any two points
    Draws a line with a CENTER linetype
    Assigns layer (say S-Anno-Dims
    Adds a CL text symbol at end of second point,
    text height depends on current text style
    orients text to same angle as line

    Regards,
    Mac

  2. #2
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    6,836

    Default Re: Centerline Part 2

    Quote Originally Posted by jocques View Post
    Pick any two points
    Use the getpoint function twice.
    Quote Originally Posted by jocques View Post
    Draws a line with a CENTER linetype
    • Change current layer as desired. Look at the CLAYER system variable. Make sure desired layer is thawed prior to change.
    • Change current linetype as desired. Look at the CELTYPE system variable.
    • Draw line with previous user specified points. You can use the command function to execute the LINE command in AutoLISP. You then need to provide the proper number of responses to this command.
    • Return layer setting to previous setting. You did save the previous value, right?
    • Return linetype setting to previous setting. Again, remember to save the previous value prior to changing system variables to return the system the same way you found it.

    Quote Originally Posted by jocques View Post
    Assigns layer (say S-Anno-Dims
    See previous step.
    Quote Originally Posted by jocques View Post
    Adds a CL text symbol at end of second point,
    text height depends on current text style
    orients text to same angle as line
    • Determine angle between previous user specified points. You can use the angle function to get this value in radians.
    • Determine current text size from text style or textsize variable. The current text size may not have the text height specified. You can thus look at the textsize system variable. If that returns 0, then you might look into the current dimension style to determine what size the text should be set.
    • Add text to last user specified point. You can use the command function to execute the TEXT or DTEXT command. You will need to provide the correct responses to complete the command.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  3. #3
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,210

    Default Re: Centerline Part 2

    Sorry for the belating I was busy
    Let me try to show you very basic things:
    Code:
    (defun C:TCL (/ *error* ang ccr clr cls clt clw cmd filename osm p1 p2 ptxt rtd tht tst txtheight)
    ;; error function by R. Robert Bell 
    ;; slightly edited
    (defun *error* (msg)
    (cond ((not msg))
          ((member msg '("Function cancelled" "quit / exit abort"))) ; <Esc>
    ((princ (strcat "Error: " msg)) ; display fatal error
    (terpri))) ; print a blank line
    (command "undo" "end")  
    ;; restore all variables we're changed
    (if osm (setvar "osmode" osm))
    (if cmd (setvar "cmdecho" cmd))
    (if clr (setvar "clayer" clr))
    (if ccr (setvar "cecolor" ccr))
    (if clt (setvar "celtype" clt))
    (if clw (setvar "celweight" clw))
    (if tst (setvar "textstyle" tst))
    (if tht (setvar "textsize" tht))
    (princ) ; clean exit
        ); _end error function
    
    ;; local defun
      
    ;; Convert value in radians to degrees
    (defun rtd (a)
      (* 180.0 (/ a pi))
    )
    ;;--------------------   main part   ------------------;;
    (command "undo" "begin")
    ;; determine system variables and set them on whatever we need
    (setq osm (getvar "osmode"))
    (setvar "osmode" 0)
    (setq cmd (getvar "cmdecho"))
    (setvar "cmdecho" 0)
    (setq clr (getvar "clayer"))
    
    (setq ccr (getvar "cecolor"))
    (setvar "cecolor" "BYLAYER")
    (setq clt (getvar "celtype"))
    
    (setq cls (getvar "celtscale"))
    (setvar "celtscale" 1.0);<-- you may want to change a linetype scale here
    (setq clw (getvar "celweight"))
    (setvar "celweight" -1);<-- (-1 is lineweight bylayer)
    (setq tst (getvar "textstyle"))
    (setq tht (getvar "textsize"))
    
    (if (= (getvar "measurement") 0);<-- check if drawing imperic
      (setq filename "acad.lin")
      (setq filename "acadiso.lin");<-- if drawing metric
      )
    ;; load linetype CENTER if it does not exist
      (if (not (tblsearch "ltype" "CENTER"))
      (command  "._-linetype" "load" "CENTER" filename "")
        )
    ;; create layer for centerline
      (if (not (tblsearch "layer" "S-Anno-Centerline"))
        (command "._-layer" "m" "S-Anno-Centerline" "c" 1 "S-Anno-Centerline" "lt" "CENTER" "S-Anno-Centerline" "")
      (command "._-layer" "t" "S-Anno-Centerline" "u" "S-Anno-Centerline" "on" "S-Anno-Dims"  "s" "S-Anno-Centerline" "")
      )
    
    (if (not (tblsearch "style" "Romans")); <-- check if text style named "Romans" does exist
      (command  "._-style" "Romantis" "Romantic.TTF" "" "" "" "N" "N"); <-- if does not exist then create one with font "Romantic.TTF"
      (setvar "textstyle" "Romans"); <-- if exist set current
      )
    
    ;; deterime current text size
    (setq txtheight (getvar "textsize"))
    (if (zerop txtheight);<-- if this equal to zero
      (setq txtheight (getvar "dimtxt"))); <-- set it equal to dimension text height
    
    (if (and (setq p1 (getpoint "\nStart Point: "))
    (setq p2 (getpoint p1 "\nEnd Point: ")));<-- if both points is specified then go to make our entities
    (progn
      (setq ang (angle p1 p2);get the line angle
          ang
     ;; change the text rotation on more right
       (cond ((or (equal (/ pi 2) ang 0.001) (equal (* pi 1.5) ang 0.001)) 0)
      ((<= 0 ang pi) (- ang (/ pi 2)))
      ((< (/ pi 2) ang (* pi 1.5)) (+ ang (/ pi 2)))
      (T (+ (/ pi 2) ang))
       )
          ang (rtd ang)
    )
     
    
      (command "._line" p1 p2 "")
      ;; create layer for text
      (if (not (tblsearch "layer" "S-Anno-Dims"))
        (command "._-layer" "m" "S-Anno-Dims" "c" 7 "S-Anno-Dims" "lt" "Continuous" "S-Anno-Dims" "")
      (command "._-layer" "t" "S-Anno-Dims" "u" "S-Anno-Dims" "on" "S-Anno-Dims"  "s" "S-Anno-Dims" "")
      )
     ;; set the current text size 
    (setvar "textsize" txtheight)
    ;; calculate the text insertion point with gap from end point = (* txtheight 0.625)
    ;; otherwise use : (setq ptxt p2)
     (setq ptxt (trans (polar p2 (angle p1 p2) (* txtheight 0.625)) 1 0))
      
     ;; think a single line text does not supports the centerline symbol
     ;; so we use multiline text instead
      
    (command "._mtext"  ptxt "J" "MC"  "R" (rtos ang) "W" "0" "\\U+2104" "")
    
      )
      )
    (*error* nil)
    (princ)
    )
    (princ "\n\t\t---\tStart command with TCL...\t---")
    (prin1)
    Let me know what is wrong with my example

    ~'J'~
    "The whole problem with the world is that fools and fanatics are always
    so certain of themselves, and wiser people so full of doubts."
    Bertrand Russell

  4. #4
    100 Club
    Join Date
    2005-01
    Posts
    115

    Default Re: Centerline Part 2

    Very nice work,
    I edited some of it to fit my needs and now have a basic understanding of .lsp Thank You!!!
    ---1 thing I did notice, when I select 2 points with osnaps that are NOT 0 or 90 Autocad prompts for an angle, then goes to mtext, then won't let me enter text.
    ---Now if I do this without osnaps it works, but.

    Here is the edited version:

    (defun C:CL (/ *error* ang ccr clr cls clt clw cmd filename osm p1 p2 ptxt rtd tht tst txtheight)
    ;; error function by R. Robert Bell
    ;; slightly edited
    (defun *error* (msg)
    (cond ((not msg))
    ((member msg '("Function cancelled" "quit / exit abort"))) ; <Esc>
    ((princ (strcat "Error: " msg)) ; display fatal error
    (terpri))) ; print a blank line
    (command "undo" "end")
    ;; restore all variables we're changed
    (if osm (setvar "osmode" 227))
    (if cmd (setvar "cmdecho" cmd))
    (if clr (setvar "clayer" clr))
    (if ccr (setvar "cecolor" ccr))
    (if clt (setvar "celtype" clt))
    (if clw (setvar "celweight" clw))
    (if tst (setvar "textstyle" tst))
    (if tht (setvar "textsize" tht))
    (princ) ; clean exit
    ); _end error function

    ;; local defun

    ;; Convert value in radians to degrees
    (defun rtd (a)
    (* 180.0 (/ a pi))
    )
    ;;-------------------- main part ------------------;;
    (command "undo" "begin")
    ;; determine system variables and set them on whatever we need
    (setq osm (getvar "osmode"))
    (setvar "osmode" 227)
    (setq cmd (getvar "cmdecho"))
    (setvar "cmdecho" 0)
    (setq clr (getvar "clayer"))

    (setq ccr (getvar "cecolor"))
    (setvar "cecolor" "BYLAYER")
    (setq clt (getvar "celtype"))

    (setq cls (getvar "celtscale"))
    (setvar "celtscale" 1.0);<-- you may want to change a linetype scale here
    (setq clw (getvar "celweight"))
    (setvar "celweight" -1);<-- (-1 is lineweight bylayer)
    (setq tst (getvar "textstyle"))
    (setq tht (getvar "textsize"))

    (if (= (getvar "measurement") 0);<-- check if drawing imperic
    (setq filename "acad.lin")
    (setq filename "acadiso.lin");<-- if drawing metric
    )
    ;; load linetype CENTER2 if it does not exist
    (if (not (tblsearch "ltype" "CENTER2"))
    (command "._-linetype" "load" "CENTER2" filename "")
    )
    ;; create layer for centerline
    (if (not (tblsearch "layer" "S-ANNO-CL"))
    (command "._-layer" "m" "S-ANNO-CL" "c" 31 "S-ANNO-CL" "lt" "CENTER2" "S-ANNO-CL" "ps" "_100d-020mm" "S-ANNO-CL" "lw" "0.20" "S-ANNO-CL" "")
    (command "._-layer" "t" "S-ANNO-CL" "u" "S-ANNO-CL" "on" "S-ANNO-DIMS" "s" "S-ANNO-CL" "")
    )

    (if (not (tblsearch "style" "csw-struct_normal")); <-- check if text style named "csw-struct_normal" does exist
    (command "._-style" "Romantis" "Romantic.TTF" "" "" "" "N" "N"); <-- if does not exist then create one with font "Romantic.TTF"
    (setvar "textstyle" "csw-struct_normal"); <-- if exist set current
    )

    ;; deterime current text size
    (setq txtheight (getvar "textsize"))
    (if (zerop txtheight);<-- if this equal to zero
    (setq txtheight (getvar "dimtxt"))); <-- set it equal to dimension text height

    (if (and (setq p1 (getpoint "\nStart Point: "))
    (setq p2 (getpoint p1 "\nEnd Point: ")));<-- if both points is specified then go to make our entities
    (progn
    (setq ang (angle p1 p2);get the line angle
    ang
    ;; change the text rotation on more right
    (cond ((or (equal (/ pi 2) ang 0.0001) (equal (* pi 1.5) ang 0.0001)) 0)
    ((<= 0 ang pi) (- ang (/ pi 2)))
    ((< (/ pi 2) ang (* pi 1.5)) (+ ang (/ pi 2)))
    (T (+ (/ pi 2) ang))
    )
    ang (rtd ang)
    )


    (command "._line" p1 p2 "")
    ;; create layer for text
    (if (not (tblsearch "layer" "S-ANNO-DIMS"))
    (command "._-layer" "m" "S-ANNO-DIMS" "c" 31 "S-ANNO-DIMS" "lt" "Continuous" "S-ANNO-DIMS" "ps" "_100d-020mm" "S-ANNO-DIMS" "lw" "0.20" "S-ANNO-DIMS" "")
    (command "._-layer" "t" "S-ANNO-DIMS" "u" "S-ANNO-DIMS" "on" "S-ANNO-DIMS" "s" "S-ANNO-DIMS" "")
    )
    ;; set the current text size
    (setvar "textsize" txtheight)
    ;; calculate the text insertion point with gap from end point = (* txtheight 1.0)
    ;; otherwise use : (setq ptxt p2)
    (setq ptxt (trans (polar p2 (angle p1 p2) (* txtheight 1.0)) 1 0))

    ;; think a single line text does not supports the centerline symbol
    ;; so we use multiline text instead

    (command "._mtext" ptxt "J" "MC" "R" (rtos ang) "W" "0" "\\U+2104" "")

    )
    )
    (*error* nil)
    (princ)
    )
    (princ "\n\t\t---\tStart command with CL...\t---")
    (prin1)
    Mac

  5. #5
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,210

    Default Re: Centerline Part 2

    Glad you got it to work
    Have a nice weekend
    Cheers

    ~'J'~
    "The whole problem with the world is that fools and fanatics are always
    so certain of themselves, and wiser people so full of doubts."
    Bertrand Russell

Similar Threads

  1. Centerline: How to?
    By Firmso in forum Revit Architecture - General
    Replies: 2
    Last Post: 2007-03-04, 11:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •