Can't write code for something that does not stay consistent ... well you can but your results won't be as intended. :wink:
The problem is that every time the color of the solid hatches (from QGIS) aren't the same.
iI tryTry: (command "_.chprop" ss "" "_LA" "DD" "")Code - Auto/Visual Lisp: [Select]
but something is going wrong !!
; Change hatch layer based on text inside hatch.
; By alan H
;;-------------------=={ UnFormat String }==------------------;;
;; ;;
;; Returns a string with all MText formatting codes removed. ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; str - String to Process ;;
;; mtx - MText Flag (T if string is for use in MText) ;;
;;------------------------------------------------------------;;
;; Returns: String with formatting codes removed ;;
;;------------------------------------------------------------;;
(defun LM:UnFormat ( str mtx / _replace rx )
(defun _replace ( new old str )
(vlax-put-property rx 'pattern old)
(vlax-invoke rx 'replace str new)
)
(if (setq rx (vlax-get-or-create-object "VBScript.RegExp"))
(progn
(setq str
(vl-catch-all-apply
(function
(lambda ( )
(vlax-put-property rx 'global actrue)
(vlax-put-property rx 'multiline actrue)
(vlax-put-property rx 'ignorecase acfalse)
(foreach pair
'(
("\032" . "\\\\\\\\")
(" " . "\\\\P|\\n|\\t")
("$1" . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]")
("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);")
("$1$2" . "\\\\(\\\\S)|[\\\\](})|}")
("$1" . "[\\\\]({)|{")
)
(setq str (_replace (car pair) (cdr pair) str))
)
(if mtx
(_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str))
(_replace "\\" "\032" str)
)
)
)
)
)
(vlax-release-object rx)
(if (null (vl-catch-all-error-p str))
str
)
)
)
)
(vl-load-com)
(defun t ( / lays )
(setq lays (list '("DD" "grass3")
'("DA" "GRASS")
'("AD" "PLANT")
'("AA" "SOLID")
'("PD" "grass2")
'("PA" "ANSI33")
'("PX" "Map06")
'("AN" "urb6")
'("XX" "ANSI33")
'("XA" "NET")
'("ΑΧ" "CORK")
)
)
(command "-layer"
"_m" "DD" "_c" "90" "" "_lw" "0.09" ""
"_m" "DA" "_c" "122" "" "_lw" "0.09" ""
"_m" "AD" "_c" "112" "" "_lw" "0.09" ""
"_m" "AA" "_c" "205" "" "_lw" "0.09" ""
"_m" "PD" "_c" "103" "" "_lw" "0.09" ""
"_m" "PA" "_c" "31" "" "_lw" "0.09" ""
"_m" "PX" "_c" "73" "" "_lw" "0.09" ""
"_m" "AN" "_c" "123" "" "_lw" "0.09" ""
"_m" "XX" "_c" "61" "" "_lw" "0.09" ""
"_m" "XA" "_c" "63" "" "_lw" "0.09" ""
"_m" "AX" "_c" "55" "" "_lw" "0.09" ""
"")
;(setq lay (cdr (assoc 8 (entget (car (entsel "\nPick text "))))))
(setq lay "KYROSI")
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(prompt "\nSelect area to be changed ")
(setq ss (ssget (list (cons 0 "MTEXT")(cons 8 lay))))
(repeat (setq x (sslength ss))
(setq ent (entget (ssname ss (setq x (- x 1)))))
(princ (setq pt (cdr (assoc 10 ent))))
(setq txt (LM:UnFormat (cdr (assoc 1 ent)) nil))
(command "zoom" "C" pt 100.0)
(vla-getboundingbox (vlax-ename->vla-object ent) 'a 'b)
(mapcar 'set '(a b) (mapcar 'vlax-safearray->list (list a b)))
;; Fuzz value = 1/2 text height
(setq n (/ (cdr (assoc 40 (entget e))) 2))
(setq ss2(ssget "_C" (mapcar '- a (list n n)) (mapcar '+ b (list n n)) '((0 . "HATCH"))))
(if (= ss2 nil)
(princ "Skipped ")
(progn
(setq ent2 (ssname ss2 0))
(foreach hlay lays
(if (= (car hlay) txt)
(progn
(command "chprop" ent2 "" "La" (car hlay) "")
(command "HATCHEDIT" ent2 "P" "Ansi33" "50" "")
)
)
)
)
)
(princ (strcat "\n" (rtos x 2 0)))
)
(princ)
)
(t)
[\code]