For my company I have created a lisp that makes the placement of a custom hatch easy.
In it, the user gets to choose the hatch scale and angle by inserting the specific angle or real.
This works perfect, but I wanted to change the scale part.
I want the user to choose between three different hatchscales:
Fine (0.5), Normal (1) and Double (2)
I tried implementing this in the lisp, but cant get it to work.
Can anybody check the codes and help me out?
The code:
(defun C:HD2 (/ *error*)
(defun *error* (msg)
(cond
((or (not msg)
(member msg
'("console break"
"function cancelled"
"quit / exit abort"
)
)
)
)
((princ (strcat "\nError: " msg)))
)
(cond (osm (setvar "osmode" osm)))
(cond (clyr (setvar "clayer" clyr)))
(cond (ccol (setvar "cecolor" ccol)))
(cond (cpat (setvar "hpname" cpat)))
(cond (hpas (setvar "hpassoc" hpas)))
(cond (hang (setvar "hpang" hang)))
(cond (csca (setvar "hpscale" csca)))
(cond (canno (setvar "cannoscale" canno)))
(command "._-layer" "on" "*" "") ;reactivate all layers
(princ)
)
;; local function, to create layer
(defun layer_set (lyr col ltp)
(setvar "cmdecho" 0)
(if (tblsearch "layer" lyr)
(command "._-layer" "t" lyr "u" lyr "on" lyr "s" lyr "")
(command "._-layer" "m" lyr "c" col lyr "lt" ltp lyr "")
)
)
;; main part
(setvar "cmdecho" 0) ; disable command line echo
(setq osm (getvar "osmode")) ;store osnap settings
(setq clyr (getvar "clayer")) ;store current layer
(setq csca (getvar "hpscale")) ;store current hpscale
(setq ccol (getvar "cecolor")) ; store current layer color
(setq cpat (getvar "hpname")) ; store the hatch pattern
(setq hpas (getvar "hpassoc")) ; store the hatch associativity
(setq hang (getvar "hpang")) ; store the hatch angle
(setq canno (getvar "cannoscale")) ; store cannoscale
(command "._-layer" "off" "*" "y" "on" "0,Arcering,Dakplan,Defpoints,Hekwerk,Tekst" "") ;zet alles layers uit, en vervolgens 0, defpoints,arcering, dakplan, hekwerk en tekst weer aan
(setvar "hpname" "Plat Dak,O") ; set hatch pattern to "Plat Dak"
(setvar "hpassoc" 1) ; set associativity
(layer_set "Arcering" "8" "Bylayer") ;create or set layer "Arcering" current,
;if this would not created before, then create them
; 8 - is color index of this layer, change to you suit
(setvar "osmode" 0)
(setvar "cecolor" "bylayer")
(setvar "cannoscale" "1:100") ;set annotation scale to 1:100. this is necessaity to make sure the hatch pattern "Plat Dak" displays correctly in oterh annotation scales
;TESTCODING
(setq scaleType (getkword "\nGewenste schaal: : "))
(cond
((OR (= scaleType "f") (= scaleType "F")) (setq hatchschaal 0.5) ) ;Fine scale
((OR (=scaleType "n") (= scaleType "N")) (setq hatchschaal 1) ) ;Normal scale
((OR (= scaleType "g") (= scaleType "G")) (setq hatchschaal 2) ) ;Double scale
) ;designate letters
(setq *hatchscale hatchschaal)
(if (null *hatchscale) (setq *hatchscale 1))
(setvar "hpscale" *hatchscale)
;END TESTCODING
;OLD CODING
;define global variable *hatchscale
;(if (null *hatchscale) (setq *hatchscale 1))
;(if *hatchscale
; (setq #B (getreal (strcat "\nVoer arceer schaal in <"(rtos *hatchscale)">: ")))
; )
; (if #B (setq *hatchscale #B) )
; (setvar "hpscale" *hatchscale)
;END OLD CODING
;define global variable *hatchangle
(if (null *hatchangle) (setq *hatchangle 0))
(if *hatchangle
(setq #A (getangle (strcat "\nSpecify hatch angle <"(rtos *hatchangle)">: ")))
)
(if #A (setq *hatchangle #A) )
(setvar "hpang" *hatchangle)
(setq ip (getpoint "\nPick internal point: "))
(while ip ;loop for adding multiple "internal points"
(command "-hatch" ip "AN" "y" "") ; add hatch, set annotative to YES
(setq ip (getpoint "\nPick next internal point, press to quit: "))
) ;while
(*error* nil) ;restore all saved system variables
(princ)
)
(princ "\nStart with hv to draw hatch")
(princ)
In it, the user gets to choose the hatch scale and angle by inserting the specific angle or real.
This works perfect, but I wanted to change the scale part.
I want the user to choose between three different hatchscales:
Fine (0.5), Normal (1) and Double (2)
I tried implementing this in the lisp, but cant get it to work.
Can anybody check the codes and help me out?
The code:
(defun C:HD2 (/ *error*)
(defun *error* (msg)
(cond
((or (not msg)
(member msg
'("console break"
"function cancelled"
"quit / exit abort"
)
)
)
)
((princ (strcat "\nError: " msg)))
)
(cond (osm (setvar "osmode" osm)))
(cond (clyr (setvar "clayer" clyr)))
(cond (ccol (setvar "cecolor" ccol)))
(cond (cpat (setvar "hpname" cpat)))
(cond (hpas (setvar "hpassoc" hpas)))
(cond (hang (setvar "hpang" hang)))
(cond (csca (setvar "hpscale" csca)))
(cond (canno (setvar "cannoscale" canno)))
(command "._-layer" "on" "*" "") ;reactivate all layers
(princ)
)
;; local function, to create layer
(defun layer_set (lyr col ltp)
(setvar "cmdecho" 0)
(if (tblsearch "layer" lyr)
(command "._-layer" "t" lyr "u" lyr "on" lyr "s" lyr "")
(command "._-layer" "m" lyr "c" col lyr "lt" ltp lyr "")
)
)
;; main part
(setvar "cmdecho" 0) ; disable command line echo
(setq osm (getvar "osmode")) ;store osnap settings
(setq clyr (getvar "clayer")) ;store current layer
(setq csca (getvar "hpscale")) ;store current hpscale
(setq ccol (getvar "cecolor")) ; store current layer color
(setq cpat (getvar "hpname")) ; store the hatch pattern
(setq hpas (getvar "hpassoc")) ; store the hatch associativity
(setq hang (getvar "hpang")) ; store the hatch angle
(setq canno (getvar "cannoscale")) ; store cannoscale
(command "._-layer" "off" "*" "y" "on" "0,Arcering,Dakplan,Defpoints,Hekwerk,Tekst" "") ;zet alles layers uit, en vervolgens 0, defpoints,arcering, dakplan, hekwerk en tekst weer aan
(setvar "hpname" "Plat Dak,O") ; set hatch pattern to "Plat Dak"
(setvar "hpassoc" 1) ; set associativity
(layer_set "Arcering" "8" "Bylayer") ;create or set layer "Arcering" current,
;if this would not created before, then create them
; 8 - is color index of this layer, change to you suit
(setvar "osmode" 0)
(setvar "cecolor" "bylayer")
(setvar "cannoscale" "1:100") ;set annotation scale to 1:100. this is necessaity to make sure the hatch pattern "Plat Dak" displays correctly in oterh annotation scales
;TESTCODING
(setq scaleType (getkword "\nGewenste schaal: : "))
(cond
((OR (= scaleType "f") (= scaleType "F")) (setq hatchschaal 0.5) ) ;Fine scale
((OR (=scaleType "n") (= scaleType "N")) (setq hatchschaal 1) ) ;Normal scale
((OR (= scaleType "g") (= scaleType "G")) (setq hatchschaal 2) ) ;Double scale
) ;designate letters
(setq *hatchscale hatchschaal)
(if (null *hatchscale) (setq *hatchscale 1))
(setvar "hpscale" *hatchscale)
;END TESTCODING
;OLD CODING
;define global variable *hatchscale
;(if (null *hatchscale) (setq *hatchscale 1))
;(if *hatchscale
; (setq #B (getreal (strcat "\nVoer arceer schaal in <"(rtos *hatchscale)">: ")))
; )
; (if #B (setq *hatchscale #B) )
; (setvar "hpscale" *hatchscale)
;END OLD CODING
;define global variable *hatchangle
(if (null *hatchangle) (setq *hatchangle 0))
(if *hatchangle
(setq #A (getangle (strcat "\nSpecify hatch angle <"(rtos *hatchangle)">: ")))
)
(if #A (setq *hatchangle #A) )
(setvar "hpang" *hatchangle)
(setq ip (getpoint "\nPick internal point: "))
(while ip ;loop for adding multiple "internal points"
(command "-hatch" ip "AN" "y" "") ; add hatch, set annotative to YES
(setq ip (getpoint "\nPick next internal point, press to quit: "))
) ;while
(*error* nil) ;restore all saved system variables
(princ)
)
(princ "\nStart with hv to draw hatch")
(princ)