TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: pedroantonio on October 16, 2014, 04:27:51 AM

Title: help with units lisp
Post by: pedroantonio 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
Title: Re: help with units lisp
Post by: kpblc 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
Title: Re: help with units lisp
Post by: Kerry on October 16, 2014, 05:00:23 AM
I don't play around with units much, BUT is NORTHDIRECTION variable something to consider ?
Title: Re: help with units lisp
Post by: pedroantonio 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
Title: Re: help with units lisp
Post by: kpblc 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).
Title: Re: help with units lisp
Post by: pedroantonio 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
Title: Re: help with units lisp
Post by: tombu 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. 
Title: Re: help with units lisp
Post by: pedroantonio 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
Title: Re: help with units lisp
Post by: ronjonp 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 (http://help.autodesk.com/view/CIV3D/2015/ENU/?guid=GUID-ABD3783D-4D11-40B0-9499-4FC7F42E155D) system variable as Kerry suggested.
Title: Re: help with units lisp
Post by: kpblc 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.
Title: Re: help with units lisp
Post by: motee-z 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)
  )
Title: Re: help with units lisp
Post by: kpblc 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!
Title: Re: help with units lisp
Post by: Pad 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)
)
Title: Re: help with units lisp
Post by: pedroantonio on October 18, 2014, 04:48:32 AM
thank you