Author Topic: help with units lisp  (Read 5611 times)

0 Members and 1 Guest are viewing this topic.

pedroantonio

  • Guest
help with units lisp
« on: October 16, 2014, 04:27:51 AM »
Hi . I have a litle problem and a need your help.
My template units is

format --> units
decimal
Grags --> clockwise
meters
genetic
Direction --> North

I use a *.fas file for a long time . The problem is that after "run " the  *.fas file and use it ,change my template units to:

format --> units
decimal
Grags --> clockwise
meters
genetic
Direction --> East

I ask from the gay who write this *.fas to help me and he sent me a file that is not working and giving me an error like this

Quote
Command: (LOAD "C:/topocad/GRD.fas") C:GRD
Command: grd
Deleting block "grd".
1 block deleted.
; error: quit / exit abort

I dont know why.

So i want to ask  if is posible to run this *.fas file  through lisp and then to change again the units

I try to write a code
Code: [Select]
(defun c:test nil
(setq units(getvar "lunits"))
(setvar "lunits" 2) ; decimal
(setq units(getvar "aunits"))
(setvar "aunits" 2) ; grads
(setq units(getvar "angbase"))
(setvar "angbase" 0)
(setq units(getvar "angdir"))
(setvar "angdir" 1) ; clockwise
    (princ)
)

I dont know how to change the direction to North

Any ideas ?
Thank

kpblc

  • Bull Frog
  • Posts: 396
Re: help with units lisp
« Reply #1 on: October 16, 2014, 04:45:41 AM »
Maybe this code will works:
Code: [Select]
(defun c:test (/ err)
  (if (vl-catch-all-error-p
        (setq err (vl-catch-all-apply
                    (function
                      (lambda ()
                        (load "C:/topocad/GRD.fas")
                        (command "grd")
                        ) ;_ end of lambda
                      ) ;_ end of function
                    ) ;_ end of vl-catch-all-apply
              ) ;_ end of setq
        ) ;_ end of vl-catch-all-error-p
    (princ (strcat "\n Error loading and executing grd.fas : " (vl-catch-all-error-message err)))
    ) ;_ end of if
  (foreach item '(("lunits" . 2)
                  ("aunits" . 2)
                  ("angbase" . 0)
                  ("angdir" . 1)
                  )
    (if (vl-catch-all-error-p
          (setq err (vl-catch-all-apply
                      (function
                        (lambda ()
                          (setvar (car item) (cdr item))
                          ) ;_ end of lambda
                        ) ;_ end of function
                      ) ;_ end of vl-catch-all-apply
                ) ;_ end of setq
          ) ;_ end of vl-catch-all-error-p
      (princ
        (strcat "\n Error settings \""
                (car item)
                "\" SysVar to value "
                (vl-princ-to-string (cdr item))
                " : "
                (vl-catch-all-error-message err)
                ) ;_ end of strcat
        ) ;_ end of princ
      ) ;_ end of if
    ) ;_ end of foreach
  (princ)
  ) ;_ end of defun
Sorry for my English.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: help with units lisp
« Reply #2 on: October 16, 2014, 05:00:23 AM »
I don't play around with units much, BUT is NORTHDIRECTION variable something to consider ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

pedroantonio

  • Guest
Re: help with units lisp
« Reply #3 on: October 16, 2014, 05:01:16 AM »
hi kpblc thank you for your time.

I check your lisp file and gives me this error

Quote
Command: (LOAD "C:/Users/Prodromos/Desktop/test.lsp") C:TEST
Command: test
grd Unknown command "GRD". 

I can not understand why because the command is the grd

kpblc

  • Bull Frog
  • Posts: 396
Re: help with units lisp
« Reply #4 on: October 16, 2014, 06:45:21 AM »
And what will happens if you type "grd" at command line after loading fas by my code?
You can change (command "grd") to one of these:
1. (vl-cmdf "grd")
2. (command-s "grd") ; only at ACAD2015
3. (c:grd).
Sorry for my English.

pedroantonio

  • Guest
Re: help with units lisp
« Reply #5 on: October 16, 2014, 11:21:29 AM »
with this change work

Code: [Select]
(defun c:test (/ err)
  (if (vl-catch-all-error-p
        (setq err (vl-catch-all-apply
                    (function
                      (lambda ()
                        (load "C:/topocad/GRD.fas")
                        (c:grd)
                        ) ;_ end of lambda
                      ) ;_ end of function
                    ) ;_ end of vl-catch-all-apply
              ) ;_ end of setq
        ) ;_ end of vl-catch-all-error-p
    (princ (strcat "\n Error loading and executing grd.fas : " (vl-catch-all-error-message err)))
    ) ;_ end of if
  (foreach item '(("lunits" . 2)
                  ("aunits" . 2)
                  ("angbase" . 0)
                  ("angdir" . 1)
                  )
    (if (vl-catch-all-error-p
          (setq err (vl-catch-all-apply
                      (function
                        (lambda ()
                          (setvar (car item) (cdr item))
                          ) ;_ end of lambda
                        ) ;_ end of function
                      ) ;_ end of vl-catch-all-apply
                ) ;_ end of setq
          ) ;_ end of vl-catch-all-error-p
      (princ
        (strcat "\n Error settings \""
                (car item)
                "\" SysVar to value "
                (vl-princ-to-string (cdr item))
                " : "
                (vl-catch-all-error-message err)
                ) ;_ end of strcat
        ) ;_ end of princ
      ) ;_ end of if
    ) ;_ end of foreach
  (princ)
  ) ;_ end of defun


but the direction still East. I want the direction be North

Thanks

tombu

  • Bull Frog
  • Posts: 289
  • ByLayer=>Not0
Re: help with units lisp
« Reply #6 on: October 16, 2014, 01:17:34 PM »
East is the norm, try listing a line and see if it gives you the direction you're looking for. 
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

pedroantonio

  • Guest
Re: help with units lisp
« Reply #7 on: October 16, 2014, 01:25:35 PM »
My template have the North ath the beginning
Then i run the grd.fas and gives me East

I want to change it again to North when lisp stop .

The test.lsp code gives me East !!!!

How to change it to North ??

Thanks

ronjonp

  • Needs a day job
  • Posts: 7527
Re: help with units lisp
« Reply #8 on: October 16, 2014, 01:47:06 PM »
My template have the North ath the beginning
Then i run the grd.fas and gives me East

I want to change it again to North when lisp stop .

The test.lsp code gives me East !!!!

How to change it to North ??

Thanks


Why don't you change the NORTHDIRECTION system variable as Kerry suggested.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

kpblc

  • Bull Frog
  • Posts: 396
Re: help with units lisp
« Reply #9 on: October 16, 2014, 03:27:33 PM »
You can add any system variables editing list
Code: [Select]
'(("lunits" . 2)
                  ("aunits" . 2)
                  ("angbase" . 0)
                  ("angdir" . 1)
                  )
Every string is dotpair: first element is system variable name, second - value to be setted. I think is's simplest way.
Sorry for my English.

motee-z

  • Newt
  • Posts: 40
Re: help with units lisp
« Reply #10 on: October 16, 2014, 08:23:52 PM »
(defun topodwg (/)
(setvar "angdir"1)
(setvar "angbase"(/ pi 2))
(setvar "aunits"2)
(setvar "dimaunit"2)
  (setvar"dimadec"4)
  (setvar "dimdec"2)
  (setvar "auprec"6)
  (setvar"insunits"6)
  )

kpblc

  • Bull Frog
  • Posts: 396
Re: help with units lisp
« Reply #11 on: October 17, 2014, 02:28:15 AM »
I think changing
Code: [Select]
(setvar "angdir"1)
(setvar "angbase"(/ pi 2))
(setvar "aunits"2)
(setvar "dimaunit"2)
  (setvar"dimadec"4)
  (setvar "dimdec"2)
  (setvar "auprec"6)
  (setvar"insunits"6)
to
Code: [Select]
(foreach item (list '("angdir" . 1)
                    (cons "angbase" (/ pi 2))
                    ("aunits" . 2)
                    ("dimaunit" . 2)
                    ("dimadec" . 4)
                    ("dimdec" . 2)
                    ("auprec" . 6)
                    ("insunits" . 6)
                    ) ;_ end of list
  (setvar (car item) (cdr item))
  ) ;_ end of foreach
is more simply to undestand and changing in future.
Why do you not use foreach or mapcar functions? It's easy!
Sorry for my English.

Pad

  • Bull Frog
  • Posts: 342
Re: help with units lisp
« Reply #12 on: October 17, 2014, 04:26:02 AM »
I simply use two very basic command lisps to change the direction if it ever gets screwed up:

Code: [Select]
;
; Lisp to modify drawing so north is 0 and clockwise angles, for some lisp routines
; to work correctly.
;
; P Bourke (Metrix Surveys) 07/04
;------------------------------------------------------------------------     

(defun C:met-n0 ()
  (setvar "CMDECHO" 0)

  ; change direction to 270 and clockwise to y
  (command "units" "" "" "" "" "90" "y") 
(prompt "\n North = 0")
  (setvar "CMDECHO" 1)
  (princ)
)

;
; Lisp to modify drawing so East is 0 and clockwise angles, for some lisp routines
; to work correctly.
;
; P Bourke (Metrix Surveys) 07/04
;------------------------------------------------------------------------     

(defun C:met-e0 ()
  (setvar "CMDECHO" 0)

  ; change direction to 0 and clockwise to n
  (command "units" "" "" "" "" "0" "n")
(prompt "\n East = 0")

  (setvar "CMDECHO" 1)
  (princ)
)

pedroantonio

  • Guest
Re: help with units lisp
« Reply #13 on: October 18, 2014, 04:48:32 AM »
thank you