Here is the new version that works the way I think it should. It uses the current scale as the make for 1 unit of distance. If the current drawing is setup to be metric, then it will grab the acadiso.pat file. It will let you cycle all the way around, style wise, without an error.
Enjoy. Comments/ideas/criticisms all welcomed.
One thing you may notice is that when you are scrolling through all the different styles, that the prompt will get looking wrong, that is because of the ' \r ' switch to the ' prompt ' function. I know one way to clean it, make a prompt string that would be longer than any there and then switch between that and the real one, but I am hoping that there is a better/cleaner way.
(defun c:HOSE ( / *error* GetHatchNames Sel Ent EntData oData nStyle cScale BasePt HatchList Pos
TogAngle tempList tempPt tempData MaxPos )
(defun *error* ( msg )
;(vl-bt)
(if oData (entmake oData))
(if Ent (entdel Ent))
(if msg (prompt (strcat "\n Error-> " msg)))
(redraw)
)
;--------------------------------
(defun GetHatchNames ( filePath / Opened tempStr tempPos tempName HatchList )
(if (setq Opened (open filePath "r"))
(while (setq tempStr (read-line Opened))
(if
(and
(= (substr tempStr 1 1) "*")
(setq tempPos (vl-string-search "," tempStr))
(setq tempName (substr tempStr 2 (1- tempPos)))
(/= (strcase tempName) "SOLID")
)
(setq HatchList (cons tempName HatchList))
)
)
)
(if Opened (close Opened))
(reverse HatchList)
)
;------------------------------------
(if
(and
(setq Sel (entsel "\n Select hatch to edit dynamicly: "))
(setq oData (entget (car Sel)))
(= (cdr (assoc 0 oData)) "HATCH")
(setq nStyle (cdr (assoc 2 oData)))
(setq cScale (cdr (assoc 41 oData)))
(setq BasePt (cadr Sel))
(setq HatchList
(GetHatchNames
(if (zerop (getvar 'Measurement))
(findfile "acad.pat")
(findfile "acadiso.pat")
)
)
)
(setq MaxPos (1- (length HatchList)))
(setq Pos (vl-position nStyle HatchList))
(setq TogAngle 0)
)
(while
(and
(not
(prompt
(strcat
"\r Current style: "
nStyle
" , Allow angle change: "
(if (zerop TogAngle) "No" "Yes")
" [Style / Angle toggle]: "
)
)
)
(setq tempList (grread T 11))
(not (equal (car tempList) 3))
)
(or
Ent
(setq Ent (car Sel))
)
(setq EntData (entget Ent '("*")))
(cond
( (equal (car tempList) 5)
(setq tempPt (cadr tempList))
(if (not (zerop (distance tempPt BasePt))) ; <- Thanks to Alan ( CAB )
(progn
(redraw)
(grdraw BasePt tempPt 7)
(setq tempData
(subst
(cons
41
;(distance tempPt BasePt)
(* (distance tempPt BasePt) cScale)
)
(assoc 41 EntData)
EntData
)
)
(if (equal TogAngle 1)
(setq tempData
(subst
(cons 52 (angle BasePt tempPt))
(assoc 52 EntData)
tempData
)
)
)
(if (entmake tempData)
(progn
(entdel Ent)
(setq Ent (entlast))
)
)
)
)
)
((equal (car tempList) 2)
(cond
( (member (cadr tempList) '(83 115))
(if (equal Pos MaxPos)
(setq Pos 0)
)
(setq nStyle (nth (setq Pos (1+ Pos)) HatchList))
(if (entmake
(subst
(cons 2 nStyle)
(assoc 2 EntData)
EntData
)
)
(progn
(entdel Ent)
(setq Ent (entlast))
)
)
)
( (member (cadr tempList) '(65 97))
(setq TogAngle (abs (1- TogAngle)))
)
)
)
)
)
)
(redraw)
(princ)
)