Jump to content

Question about linetypes / rotation within


MarcoW

Recommended Posts

I might be in the wrong forum, if so please move me there where it belongs:

 

See image below, if I create linetypes like the acad GAS_LINE the text is not rotating the way I'd like it.

 

 
*GAS_LINE,Gas line ----GAS----GAS----GAS----GAS--
A,12.7,-5.08,["GAS",STANDARD,S=2.54,R=0.0,X=-2.54,Y=-1.27],-6.35

 

The "R" is for rotation, from x-axis... If "R" would be "A" it rotates from the actual linepiece... Can anyone follow me ??

 

Anyway... I would like to have the linetype "readable", see image for example.

 

How would one accomplish that kind of thing? Is there something like a sysvariable that I can use or must it be a lisp routine that solves this?

 

Thanks for all the help !!

ltype.jpg

Link to comment
Share on other sites

  • Replies 27
  • Created
  • Last Reply

Top Posters In This Topic

  • The Buzzard

    11

  • MarcoW

    7

  • Lee Mac

    5

  • lpseifert

    2

Top Posters In This Topic

Posted Images

Can't do it using 1 continuous pline, you'll need 2 different polylines; or break it in the LR corner and use a reverse polyline routine to get what you want.

Link to comment
Share on other sites

I'm sorry but could not resist:

 

priest.gif Our father who art in modelspace... "I am shure someone will come up with a solution" he said rather serious.

 

smarty.gif "Yeah right, but not me!" the first one said.

 

cursing.gif "And who might you be, you little dwarf"?" the priest asked in anger.

 

rimshot.gif "Well I am a drummer in a band, and I was just $%^#! ing you around". "Ow hi. I am John, Ringo, and Freddy" the. We are all in the same band...

 

[Hush..]

 

One could feel the tension... it went quiet and in the silence you could hear a pindrop fall...

 

Then all of a sudden the priest revealed his true inner being:

16.gif "I am evil itself and I will punnish you and the rest of you band!" he shouted.

 

Hah, they would all laugh about him "Punnish us..."

point%20and%20laugh.gif "Come on let's get his Horse !!!"

 

THey ran outside and there it happened: the horse got beaten up pretty bad: deadhorse.gif

 

And so it went that very day, this is the story of what happened to the priests horse.

 

Well of course there was some more fight outside attachment.php?attachmentid=4371&stc=1&d=110020 for John felt sick about the beaten horse, he wanted it to stop.

 

John -->puke.gifVery sick...

 

In the end they came up with the idea that someone should help the priest. Considering the dead horse they thought they owed him one.

 

They came up with a routine, as desired. Not to please the priest but to stay on the forum CadTutor, to avoid getting banned banned.gif

 

 

So the story ends with a happy priest, a dead horse and a great routine.

 

---

 

This was no joke. All we need to do now is search google.gifthe routine for the original got lost during few private moments (yeah you know toilet.gif)

Link to comment
Share on other sites

ha, well if lpseifert, lee mac, and alanjt all agree that it's not possible then that's written in stone. All three of those guys are what most people like to call "guru's" of CAD customization. 8)

Link to comment
Share on other sites

I might be in the wrong forum, if so please move me there where it belongs:

 

See image below, if I create linetypes like the acad GAS_LINE the text is not rotating the way I'd like it.

 

 
*GAS_LINE,Gas line ----GAS----GAS----GAS----GAS--
A,12.7,-5.08,["GAS",STANDARD,S=2.54,R=0.0,X=-2.54,Y=-1.27],-6.35

 

The "R" is for rotation, from x-axis... If "R" would be "A" it rotates from the actual linepiece... Can anyone follow me ??

 

Anyway... I would like to have the linetype "readable", see image for example.

 

How would one accomplish that kind of thing? Is there something like a sysvariable that I can use or must it be a lisp routine that solves this?

 

Thanks for all the help !!

 

 

Marcow,

 

Attached is a program I helped another member with. It draws custom linetype from a file with text in it. The program actually rotates the line from its mid-point to correct the reading direction.

 

Give the attached a try to see if this is what you need. Then review the program to see how this is done. Its fully commented.

 

Note: Make sure all three files are together and in the Acad Search Support Path.

 

Look in the loop to see what is happening.

 

;
; Output Function
;
(defun ESS_OF ()                                                              ;Define function
 (setq c "84")                                                               ;Set Layer Color
 (setq d "0.3")                                                              ;Set Line Weight
 (if                                                                         ;If the following returns true
   (= LCAT "C1")                                                             ;LCAT = C1
   (setq a (strcat "CCC_DR_"SIZE"_"HOLE)                                     ;Set Linetype
         b (strcat "CCC_SERVICES_EXISTING_Drainage_Storm_Sewer_"SIZE"_"HOLE) ;Set Layer Name
   )                                                                         ;End setq
 )                                                                           ;End if
 (if                                                                         ;If the following returns true
   (= LCAT "C2")                                                             ;LCAT = C2
   (setq a (strcat "CCC_DR_"SIZE)                                            ;Set Linetype
         b (strcat "CCC_SERVICES_EXISTING_Drainage_Storm_Sewer_"SIZE)        ;Set Layer Name
   )                                                                         ;End setq
 )                                                                           ;End if
 (if                                                                         ;If the following returns true
   (not                                                                      ;Verify that an item evaluates to nil
     (tblsearch "LTYPE" a)                                                   ;Search drawing for linetype
   )                                                                         ;If linetype not found
   (command "_.-linetype" "_l" a "CCC_Drainage.lin" "")                      ;Load linetype, from file
 )                                                                           ;End if
 (ESS_LC b c a d)                                                            ;Go to ESS_LC ~ Layer Create Function, Layer Name/Color/Linetype/Lineweight
 (setvar "angbase" 0.0000)                                                   ;Set Angle Base to 0
 (setvar "angdir"  0)                                                        ;Set Angle Direction to 0
 (setvar "orthomode" 1)                                                      ;Turn on Orthomode
 (setvar "osmode"    16383)                                                  ;Turn on all Object Snaps
 (setq PT01 (getpoint "\nEnter the line start point:"))                      ;Get the first point of line
 [color=red](while                                                                      ;Evaluate expression till nill[/color]
[color=red]   (/= nil                                                                   ;If not =[/color]
[color=red]     (setq PT02 (getpoint PT01 "\nEnter the line end point:"))               ;Set point 2[/color]
[color=red]   )                                                                         ;End if not[/color]
[color=red]   (setvar "osmode" 0)                                                       ;Turn off all Object Snaps[/color]
[color=red]   (if                                                                       ;If the following returns true[/color]
[color=red]     (= LCAT "C1")                                                           ;LCAT ~ Line Category = C1[/color]
[color=red]     (progn                                                                  ;Then do the following[/color]
[color=red]       (command "_.pline" PT01 PT02 "")                                      ;Pline command[/color]
[color=red]       (setq RADIANS (angle PT01 PT02))                                      ;Get line angle in radians[/color]
[color=red]       (setq DEGREES (ESS_RTD RADIANS))                                      ;Convert radians to degrees[/color]
[color=red]       (setq PLEN (distance PT01 PT02))                                      ;Get the line distance[/color]
[color=red]       (setq MIDPT (polar PT01 (ESS_DTR DEGREES)(/ PLEN 2.0)))               ;Set the midpoint of the line[/color]
[color=red]       (setq PT01 PT02)                                                      ;Set point 1 from point 2[/color]
[color=red]       (setvar "osmode" 16383)                                               ;Turn on all Object Snaps[/color]
[color=red]       (if                                                                   ;If the following returns true[/color]
[color=red]         (and                                                                ;Return the logical AND of the supplied arguments [/color]
[color=red]           (>  DEGREES 90.0)                                                 ;Degrees is greater than 90[/color]
[color=red]           (<= DEGREES 270.0)                                                ;And less than or equal to 270[/color]
[color=red]         )                                                                   ;End and[/color]
[color=red]         (command "_.rotate" "last" "" MIDPT "180.0")                        ;Rotate the line on it mid-point 180 degrees[/color]
[color=red]       )                                                                     ;End if[/color]
[color=red]     )[/color]                                                                       ;Otherwise...
   )                                                                         ;End if
   (if                                                                       ;If the following returns true
     (= LCAT "C2")                                                           ;LCAT ~ Line Category = C2
     (progn                                                                  ;Then do the following
       (command "_.pline" PT01 PT02 "")                                      ;Pline command
       (setq PT01 PT02)                                                      ;Set point 1 from point 2
       (setvar "osmode" 16383)                                               ;Turn on all Object Snaps
     )                                                                       ;Otherwise...
   )                                                                         ;End if
 )                                                                           ;End while
 (setq *error* temperr)                                                      ;Restore error
 (setvar "cmdecho"   SUCE)                                                   ;Restore Saved User Command Echo
 (setvar "orthomode" SUOM)                                                   ;Restore Saved User Orthomode
 (setvar "osmode"    SUSM)                                                   ;Restore Saved User Object Snapmode
 (setvar "angbase"   SUAB)                                                   ;Restore Saved User Angle Base
 (setvar "angdir"    SUAD)                                                   ;Restore Saved User Angle Direction
 (princ)                                                                     ;Exit quietly
)                                                                             ;End defun
;

 

 

 

Good Luck,

The Buzzard

ESS.zip

Link to comment
Share on other sites

Rather than draw one continuous polyline, You are drawing polyline sections and rotating the sections that are greater than 90 degrees and less than or equal to 270 degrees.

 

Very simple concept.

Document1.jpg

Link to comment
Share on other sites

The attached routine does only the Gas_Line linetype. I removed the DCL and run this routine from the command prompt to make things more simple. This routine will draw your linetype as if it were one continuous polyline when in reality they are individual polylines. If you are actually looking for this in one polyline, Its not going to happen as lpseifert had already mentioned.

 

If this does not work for you, Then I am out of answers.

 

;//////////////////////////////////////////////////////////////////////////
;
; Start-Up Function
;
(defun C:GL ()                                                             ;Define function
 (GL_MF)                                                                  ;Go to GL_MF ~ Main Function
 (princ)                                                                  ;Exit quietly
)                                                                          ;End defun
(princ "\nGL.lsp Loaded....")                                              ;print message to command line
(princ "\nType GL to start program.")                                      ;print message to command line
;
;//////////////////////////////////////////////////////////////////////////
;
; Main Function
;
(defun GL_MF (/ SUCE SUOM SUSM SUAB SUAD MIDPT PLEN  PT01 PT02)            ;Define function, Declare local variables
;                 
 (setq SUCE (getvar "cmdecho"))                                           ;Save User Command Echo
 (setq SUOM (getvar "orthomode"))                                         ;Save User Orthomode
 (setq SUSM (getvar "osmode"))                                            ;Save User Object Snapmode
 (setq SUAB (getvar "angbase"))                                           ;Save User Angle Base
 (setq SUAD (getvar "angdir"))                                            ;Save User Angle Direction
 (setq temperr *error*)                                                   ;Save Temporary Error
 (setq *error* ESS_ET)                                                    ;Go to GL_ET ~ Error Trap Function
;
 (GL_LC "GAS LINE" "3" "GAS_LINE" "")                                     ;Go to GL_LC Layer Function, Layer Name, Color, Linetype & Lineweight
;
 (setvar "angbase" 0.0000)                                                ;Set Angle Base to 0
 (setvar "angdir"  0)                                                     ;Set Angle Direction to 0
 (setvar "orthomode" 1)                                                   ;Turn on Orthomode
 (setvar "osmode"    SUSM)                                                ;Turn on User Object Snaps
 [color=red](setq PT01 (getpoint "\nEnter the line start point:"))                   ;Get the first point of line[/color]
[color=red](while                                                                   ;Evaluate expression till nill[/color]
[color=red](/= nil                                                                ;If not =[/color]
[color=red]  (setq PT02 (getpoint PT01 "\nEnter the line end point:"))            ;Set point 2[/color]
[color=red])                                                                      ;End if not[/color]
[color=red](setvar "osmode" 0)                                                    ;Turn off all Object Snaps[/color]
[color=red](progn                                                                 ;Then do the following[/color]
[color=red]  (command "_.pline" PT01 PT02 "")                                     ;Pline command[/color]
[color=red]  (setq RADIANS (angle PT01 PT02))                                     ;Get line angle in radians[/color]
[color=red]  (setq DEGREES (GL_RTD RADIANS))                                      ;Convert radians to degrees[/color]
[color=red]  (setq PLEN (distance PT01 PT02))                                     ;Get the line distance[/color]
[color=red]  (setq MIDPT (polar PT01 (GL_DTR DEGREES)(/ PLEN 2.0)))               ;Set the midpoint of the line[/color]
[color=red]  (setq PT01 PT02)                                                     ;Set point 1 from point 2[/color]
[color=red]  (setvar "osmode" SUSM)                                               ;Turn on User Object Snaps[/color]
[color=red]  (if                                                                  ;If the following returns true[/color]
[color=red]    (and                                                               ;Return the logical AND of the supplied arguments [/color]
[color=red]      (>  DEGREES 90.0)                                                ;Degrees is greater than 90[/color]
[color=red]      (<= DEGREES 270.0)                                               ;And less than or equal to 270[/color]
[color=red]    )                                                                  ;End and[/color]
[color=red]    (command "_.rotate" "last" "" MIDPT "180.0")                       ;Rotate the line on it mid-point 180 degrees[/color]
[color=red]  )                                                                    ;End if[/color]
   [color=red])                                                                      ;Otherwise...[/color]
 [color=red])                                                                        ;End while[/color]
 (setq *error* temperr)                                                   ;Restore error
 (setvar "cmdecho"   SUCE)                                                ;Restore Saved User Command Echo
 (setvar "orthomode" SUOM)                                                ;Restore Saved User Orthomode
 (setvar "osmode"    SUSM)                                                ;Restore Saved User Object Snapmode
 (setvar "angbase"   SUAB)                                                ;Restore Saved User Angle Base
 (setvar "angdir"    SUAD)                                                ;Restore Saved User Angle Direction
 (princ)                                                                  ;Exit quietly
)                                                                          ;End defun
;
;//////////////////////////////////////////////////////////////////////////
;
; Degrees to Radians Function
;
(defun GL_DTR (DEGREES)                                                    ;Define function, DEGREES is the argument
(* pi (/ DEGREES 180.0))                                                  ;Calculate Degress to radians
)                                                                          ;End defun
;
;//////////////////////////////////////////////////////////////////////////
;
; Radians to Degrees Function
;
(defun GL_RTD (RADIANS)                                                    ;Define function, RADIANS is the argument
 (* 180.0 (/ RADIANS pi))                                                 ;Calculate Radians to degress
)                                                                          ;End defun
;
;//////////////////////////////////////////////////////////////////////////
;
; Layer Create Function
;
(defun GL_LC (NLAY LCLR LTYP LWGT / LAY FRZ)                               ;Define function, Declare local variables and arguments
;
 (setq CLAY (getvar "clayer"))                                            ;Get the current layer
 (setq LAY (tblsearch "layer" NLAY))                                      ;Search drawing to find layer, Note: (NOT USED)
 (if                                                                      ;If the following returns true
   (not LAY)                                                              ;Layer not in drawing
   (command "_.layer" "m" NLAY "c" LCLR "" "lt" LTYP "" "lw" LWGT "" "")  ;Layer command
   (progn                                                                 ;Then do the following
     (setq FRZ (cdr (assoc 70 LAY)))                                      ;Variable FRZ is frozen layer
     (if                                                                  ;If the following returns true
       (= FRZ 65)                                                         ;Layer frozen from last edit
       (progn                                                             ;Then do the following
         (command "_.layer" "t" NLAY "")                                  ;Thaw layer
         (command "_.layer" "s" NLAY "")                                  ;Set layer
       )                                                                  ;Otherwise...
       (command "_.layer" "s" NLAY "")                                    ;Set layer
     )                                                                    ;End if
   )                                                                      ;Otherwise...
 )                                                                        ;End if
 (princ)                                                                  ;Exit quietly
)                                                                          ;End defun
;
;//////////////////////////////////////////////////////////////////////////
;
; Error Trap Function
;
(defun GL_ET (errmsg)                                                      ;Define function, errmsg is the argument
 (command nil nil nil)                                                    ;When escape selected
 (if                                                                      ;If the following returns true
   (not                                                                   ;Verify that an item evaluates to nil
     (member errmsg '("console break" "Function Cancelled"))              ;Search list for an occurence of an expression
   )                                                                      ;End not
   (princ (strcat "\nError:" errmsg))                                     ;Print message to command line
 )                                                                        ;End if
 (setvar "cmdecho"   SUCE)                                                ;Restore Saved User Command Echo
 (setvar "orthomode" SUOM)                                                ;Restore Saved User Orthomode
 (setvar "osmode"    SUSM)                                                ;Restore Saved User Object Snapmode
 (setvar "angbase"   SUAB)                                                ;Restore Saved User Angle Base
 (setvar "angdir"    SUAD)                                                ;Restore Saved User Angle Direction
 (princ "\nError, Restoring Variables.")                                  ;Print message to command line
 (terpri)                                                                 ;Terminate print
 (setq *error* temperr)                                                   ;Restore error
 (princ)                                                                  ;Exit quietly
)                                                                          ;End defun
;
;//////////////////////////////////////////////////////////////////////////

Document1.jpg

GL.lsp

Link to comment
Share on other sites

Buzzard,

 

Thanks I have tried and it works!

Did not think it would be that sipmle...

 

You basically draw a line between 2 given points and rotate the "last" created line if it is under specific angle. Well of course in a while loop.

 

It is complete for I see an error trap, osnap to "0", and even a lot of explainations in there. I will learn from it.

 

Thank you again.

Marco.

Link to comment
Share on other sites

Buzzard,

 

Thanks I have tried and it works!

Did not think it would be that sipmle...

 

You basically draw a line between 2 given points and rotate the "last" created line if it is under specific angle. Well of course in a while loop.

 

It is complete for I see an error trap, osnap to "0", and even a lot of explainations in there. I will learn from it.

 

Thank you again.

Marco.

 

Glad this works for you. I am sure you can add other linetypes to this same routine if you wanted.

The ESS.lsp & ESS.dcl with the CCC_Drainage.lin is one way to do various linetypes outside of the Acad.lin or Acadiso.lin.

It uses the same principle except for the linetype loading.

 

The routine was done in a way for completeness. If you are going to change user settings, Then it pays to save them at the begining of the routine and restore them at the end. The error trap is for when you escape in mid-command, The user settings will still be restored as well. Everything in that program is there for a reason. So I hope these are good examples to learn from.

 

Try not to beat-up on any horses.

 

Good Luck,

The Buzzard

Link to comment
Share on other sites

Marcow,

 

I had to correct the line indicated in RED for the error trap. See below. I must have been in a hurry.

 

Sorry about that.

The Buzzard

;//////////////////////////////////////////////////////////////////////////
; Start-Up Function
(defun C:GL ()                                                             ;Define function
 (GL_MF)                                                                  ;Go to GL_MF ~ Main Function
 (princ)                                                                  ;Exit quietly
)                                                                          ;End defun
(princ "\nGL.lsp Loaded....")                                              ;print message to command line
(princ "\nType GL to start program.")                                      ;print message to command line
;;;//////////////////////////////////////////////////////////////////////////
; Main Function
(defun GL_MF (/ SUCE SUOM SUSM SUAB SUAD MIDPT PLEN  PT01 PT02)            ;Define function, Declare local variables
 (setq SUCE (getvar "cmdecho"))                                           ;Save User Command Echo
 (setq SUOM (getvar "orthomode"))                                         ;Save User Orthomode
 (setq SUSM (getvar "osmode"))                                            ;Save User Object Snapmode
 (setq SUAB (getvar "angbase"))                                           ;Save User Angle Base
 (setq SUAD (getvar "angdir"))                                            ;Save User Angle Direction
 (setq SUCL (getvar "clayer"))                                            ;Save User Current Layer
 (setq temperr *error*)                                                   ;Save Temporary Error
 [color=red](setq *error* GL_ET)                                                     ;Go to GL_ET ~ Error Trap Function[/color]
 (GL_LC "GAS LINE" "3" "GAS_LINE" "")                                     ;Go to GL_LC Layer Function, Layer Name, Color, Linetype & Lineweight
 (setvar "cmdecho" 0)                                                     ;Set Command Echo to 0
 (setvar "angbase" 0.0000)                                                ;Set Angle Base to 0
 (setvar "angdir"  0)                                                     ;Set Angle Direction to 0
 (setvar "orthomode" 1)                                                   ;Turn on Orthomode
 (setvar "osmode"    SUSM)                                                ;Turn on User Object Snaps
 (setq PT01 (getpoint "\nEnter the line start point:"))                   ;Get the first point of line
 (while                                                                   ;Evaluate expression till nill
   (/= nil                                                                ;If not =
     (setq PT02 (getpoint PT01 "\nEnter the line end point:"))            ;Set point 2
   )                                                                      ;End if not
   (setvar "osmode" 0)                                                    ;Turn off all Object Snaps
   (progn                                                                 ;Then do the following
     (command "._pline" PT01 PT02 "")                                     ;Pline command
     (setq RADIANS (angle PT01 PT02))                                     ;Get line angle in radians
     (setq DEGREES (GL_RTD RADIANS))                                      ;Convert radians to degrees
     (setq PLEN (distance PT01 PT02))                                     ;Get the line distance
     (setq MIDPT (polar PT01 (GL_DTR DEGREES)(/ PLEN 2.0)))               ;Set the midpoint of the line
     (setq PT01 PT02)                                                     ;Set point 1 from point 2
     (setvar "osmode" SUSM)                                               ;Turn on User Object Snaps
     (if                                                                  ;If the following returns true
       (and                                                               ;Return the logical AND of the supplied arguments 
         (>  DEGREES 90.0)                                                ;Degrees is greater than 90
         (<= DEGREES 270.0)                                               ;And less than or equal to 270
       )                                                                  ;End and
       (command "._rotate" "_last" "" MIDPT "180.0")                      ;Rotate the line on it mid-point 180 degrees
     )                                                                    ;End if
   )                                                                      ;Otherwise...
 )                                                                        ;End while
 (setq *error* temperr)                                                   ;Restore error
 (setvar "cmdecho"   SUCE)                                                ;Restore Saved User Command Echo
 (setvar "orthomode" SUOM)                                                ;Restore Saved User Orthomode
 (setvar "osmode"    SUSM)                                                ;Restore Saved User Object Snapmode
 (setvar "angbase"   SUAB)                                                ;Restore Saved User Angle Base
 (setvar "angdir"    SUAD)                                                ;Restore Saved User Angle Direction
 (setvar "clayer"    SUCL)                                                ;Restore Saved User Current Layer
 (princ)                                                                  ;Exit quietly
)                                                                          ;End defun
;//////////////////////////////////////////////////////////////////////////
; Degrees to Radians Function
(defun GL_DTR (DEGREES)                                                    ;Define function, DEGREES is the argument
(* pi (/ DEGREES 180.0))                                                  ;Calculate Degress to radians
)                                                                          ;End defun
;//////////////////////////////////////////////////////////////////////////
; Radians to Degrees Function
(defun GL_RTD (RADIANS)                                                    ;Define function, RADIANS is the argument
 (* 180.0 (/ RADIANS pi))                                                 ;Calculate Radians to degress
)                                                                          ;End defun
;//////////////////////////////////////////////////////////////////////////
; Layer Create Function
(defun GL_LC (NLAY LCLR LTYP LWGT / LAY FRZ)                               ;Define function, Declare local variables and arguments
 (setq CLAY (getvar "clayer"))                                            ;Get the current layer
 (setq LAY (tblsearch "layer" NLAY))                                      ;Search drawing to find layer, Note: (NOT USED)
 (if                                                                      ;If the following returns true
   (not LAY)                                                              ;Layer not in drawing
   (command "._layer" "_m" NLAY "_c" LCLR "" "_lt" LTYP "" "_lw" LWGT "") ;Layer command
   (progn                                                                 ;Then do the following
     (setq FRZ (cdr (assoc 70 LAY)))                                      ;Variable FRZ is frozen layer
     (if                                                                  ;If the following returns true
       (= FRZ 65)                                                         ;Layer frozen from last edit
       (progn                                                             ;Then do the following
         (command "._layer" "_t" NLAY "")                                 ;Thaw layer
         (command "._layer" "_s" NLAY "")                                 ;Set layer
       )                                                                  ;Otherwise...
       (command "._layer" "_s" NLAY "")                                   ;Set layer
     )                                                                    ;End if
   )                                                                      ;Otherwise...
 )                                                                        ;End if
 (princ)                                                                  ;Exit quietly
)                                                                          ;End defun
;//////////////////////////////////////////////////////////////////////////
; Error Trap Function
(defun GL_ET (errmsg)                                                      ;Define function, errmsg is the argument
 (command nil nil nil)                                                    ;When escape selected
 (if                                                                      ;If the following returns true
   (not                                                                   ;Verify that an item evaluates to nil
     (member errmsg '("console break" "Function Cancelled"))              ;Search list for an occurence of an expression
   )                                                                      ;End not
   (princ (strcat "\nError:" errmsg))                                     ;Print message to command line
 )                                                                        ;End if
 (setvar "cmdecho"   SUCE)                                                ;Restore Saved User Command Echo
 (setvar "orthomode" SUOM)                                                ;Restore Saved User Orthomode
 (setvar "osmode"    SUSM)                                                ;Restore Saved User Object Snapmode
 (setvar "angbase"   SUAB)                                                ;Restore Saved User Angle Base
 (setvar "angdir"    SUAD)                                                ;Restore Saved User Angle Direction
 (setvar "clayer"    SUCL)                                                ;Restore Saved User Current Layer
 (princ "\nError, Restoring Variables.")                                  ;Print message to command line
 (terpri)                                                                 ;Terminate print
 (setq *error* temperr)                                                   ;Restore error
 (princ)                                                                  ;Exit quietly
)                                                                          ;End defun
;//////////////////////////////////////////////////////////////////////////

 

Also I fixed an Unknown command "GL" Press F1 for help error

 

There was an extra "" quote in this line.

 

; Layer Create Function
(defun GL_LC (NLAY LCLR LTYP LWGT / LAY FRZ)                               ;Define function, Declare local variables and arguments
 (setq CLAY (getvar "clayer"))                                            ;Get the current layer
 (setq LAY (tblsearch "layer" NLAY))                                      ;Search drawing to find layer, Note: (NOT USED)
 (if                                                                      ;If the following returns true
   (not LAY)                                                              ;Layer not in drawing
   [color=red](command "._layer" "_m" NLAY "_c" LCLR "" "_lt" LTYP "" "_lw" LWGT "") ;Layer command[/color]
   (progn                                                                 ;Then do the following
     (setq FRZ (cdr (assoc 70 LAY)))                                      ;Variable FRZ is frozen layer
     (if                                                                  ;If the following returns true
       (= FRZ 65)                                                         ;Layer frozen from last edit
       (progn                                                             ;Then do the following
         (command "._layer" "_t" NLAY "")                                 ;Thaw layer
         (command "._layer" "_s" NLAY "")                                 ;Set layer
       )                                                                  ;Otherwise...
       (command "._layer" "_s" NLAY "")                                   ;Set layer
     )                                                                    ;End if
   )                                                                      ;Otherwise...
 )                                                                        ;End if
 (princ)                                                                  ;Exit quietly
)                                                                          ;End defun

 

See the attached below for the complete program.

GL.lsp

Link to comment
Share on other sites

Buzzard,

 

I notice that you use a lot of variables to store and reset your sys Vars:

 

(setq SUCE (getvar "cmdecho"))                                           ;Save User Command Echo
 (setq SUOM (getvar "orthomode"))                                         ;Save User Orthomode
 (setq SUSM (getvar "osmode"))                                            ;Save User Object Snapmode
 (setq SUAB (getvar "angbase"))                                           ;Save User Angle Base
 (setq SUAD (getvar "angdir"))

 

Why not just store them all at once:

 

(setq OldVars (mapcar 'getvar '("CMDECHO" "ORTHOMODE" "OSMODE" "ANGBASE" "ANGDIR")))

 

Lee

Link to comment
Share on other sites

Buzzard,

 

I notice that you use a lot of variables to store and reset your sys Vars:

 

(setq SUCE (getvar "cmdecho"))                                           ;Save User Command Echo
 (setq SUOM (getvar "orthomode"))                                         ;Save User Orthomode
 (setq SUSM (getvar "osmode"))                                            ;Save User Object Snapmode
 (setq SUAB (getvar "angbase"))                                           ;Save User Angle Base
 (setq SUAD (getvar "angdir"))

 

Why not just store them all at once:

 

(setq OldVars (mapcar 'getvar '("CMDECHO" "ORTHOMODE" "OSMODE" "ANGBASE" "ANGDIR")))

 

Lee

 

 

That does not seem like a bad idea, But in some instance I may want to use the old settings somewhere within the program. I set the program up to use the Users own object snaps when called for. Thats not flexible enough for me if I place all settings under one variable.

 

See below:

 

  (while                                                                   ;Evaluate expression till nill
   (/= nil                                                                ;If not =
     (setq PT02 (getpoint PT01 "\nEnter the line end point:"))            ;Set point 2
   )                                                                      ;End if not
   (setvar "osmode" 0)                                                    ;Turn off all Object Snaps
   (progn                                                                 ;Then do the following
     (command "_.pline" PT01 PT02 "")                                     ;Pline command
     (setq RADIANS (angle PT01 PT02))                                     ;Get line angle in radians
     (setq DEGREES (GL_RTD RADIANS))                                      ;Convert radians to degrees
     (setq PLEN (distance PT01 PT02))                                     ;Get the line distance
     (setq MIDPT (polar PT01 (GL_DTR DEGREES)(/ PLEN 2.0)))               ;Set the midpoint of the line
     (setq PT01 PT02)                                                     ;Set point 1 from point 2
     [color=red](setvar "osmode" SUSM)                                               ;Turn on User Object Snaps[/color]
     (if                                                                  ;If the following returns true
       (and                                                               ;Return the logical AND of the supplied arguments 
         (>  DEGREES 90.0)                                                ;Degrees is greater than 90
         (<= DEGREES 270.0)                                               ;And less than or equal to 270
       )                                                                  ;End and
       (command "_.rotate" "last" "" MIDPT "180.0")                       ;Rotate the line on it mid-point 180 degrees
     )                                                                    ;End if
   )                                                                      ;Otherwise...
 )                                                                        ;End while

 

I am not sure, But would I use the Extract List Items function you were using at one time in that case to get what you would need for a situation such as that?

 

Besides the function below,

Seems to me that more coding will be involved just to turn on the Saved Users Snaps. I do not think its worth it.

 

;;;Extract List Items Function

(defun GL_ELI (lst items)                                          ;Define function ~ lst & items are the arguments
 (mapcar '(lambda (i) (nth i lst)) items)                          ;Return list, Define anonymous function, Return nth element of list
)                                                                   ;End define function

 

 

Thanks Anyway,

The Buzzard

Link to comment
Share on other sites

No, its not too much more - you just need to plan things a little :)

 

For example, structure the list like something like this:

 

(setq OldVars (mapcar 'getvar '("OSMODE" "CMDECHO"...

 

Then to switch snaps back on:

 

(setvar "OSMODE" (car OldVars))

 

Or, if it is further down in the list, just use nth :)

Link to comment
Share on other sites

No, its not too much more - you just need to plan things a little :)

 

For example, structure the list like something like this:

 

(setq OldVars (mapcar 'getvar '("OSMODE" "CMDECHO"...

 

Then to switch snaps back on:

 

(setvar "OSMODE" (car OldVars))

 

Or, if it is further down in the list, just use nth :)

 

 

I never gave that much thought, Very nice Lee.

I will try to keep that in mind on my next code.

 

Thanks,

The Buzzard

Link to comment
Share on other sites

You're welcome, its much more convenient when setting multiple Sys vars.

 

For instance, quite a few programs will only alter CMDECHO OSMODE and CLAYER, for example.

 

So the code can be something like:

 

(setq VarList '("CLAYER" "CMDECHO" "OSMODE"))

(setq OldVars (mapar 'getvar VarList))

Then when switching off CMDECHO, OSMODE:

 

(mapcar 'setvar (cdr VarList) '(0 0))

And in the Error Handler:

 

(defun *error* (msg)
 (if OldVars (mapcar 'setvar VarList OldVars))
 (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
     (princ (strcat "\n** Error: " msg " **")))
 (princ))

Hope this helps,

 

Lee

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