Jump to content

Syntax to specify non-standard colours


pixel8er

Recommended Posts

I think I might stick with the standard ACI colours..

(setq c 150)

 

seems like the True Colours and Pantone Colours might be too hard to implement

Edited by pixel8er
Edit code
Link to comment
Share on other sites

On 11/16/2018 at 9:55 PM, pixel8er said:

Close. I noticed the linework changed colour, but it's the hatch I want to be coloured depending on the closed polyline m² area. Different m² areas will be different hatch colours. I'd also like to put each m² hatch on a seperate layer. 

Maybe this will give you some ideas:

;; Written by PBEJSE on CADTutor
;; Post #4 https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/multiple-polyline-area-labels/td-p/3459894
;; Relies on TEXTSIZE variable for text size
;; 280316 - Tharwat updated field properties in post #2 in above link
;; 040416 - Tharwat updated to add hatch based on area ranges

(command "-dimstyle" "R" "Standard")

(defun c:mfah (/ acsp ar bitversion clr e h id ins ln o p ptlist scale ss strfield sum txt verts)
  (setq ins (getvar "insunits"))
  (cond	((= (setq ins (getvar "insunits")) 4) ;if insunits=4 then apply 1 x cannoscale
	 (setvar "dimscale" (/ 1.0 (getvar "CANNOSCALEVALUE")))
	)
	((= ins 6)			;if insunits=6 then apply 0.001 x cannoscale
	 (setvar "dimscale" (/ 0.001 (getvar "CANNOSCALEVALUE")))
	)
  )
  (setq scale (getvar "DIMSCALE"))
  (setq ln (strcat "U-TEXT-AREA-" (rtos scale 2 0)))
  (command "-LAYER" "m" ln "co" "7" ln "p" "p" ln "")
  (setvar "TEXTSTYLE" "Standard")
  (setvar "TEXTSIZE" (* 1.8 (getvar "DIMSCALE")))
  (setq	bitversion (> (strlen (vl-prin1-to-string (vlax-get-acad-object))) 40)
	acsp	   (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
  )
  (if (setq ss (ssget "_X" '((0 . "LWPOLYLINE") (-4 . "&") (70 . 1) (410 . "Model"))))
    (repeat (sslength ss)
      (setq e	  (ssname ss 0)
	    sum	  '(0 0)
	    verts (cdr (assoc 90 (entget e)))
      )
      (setq ptlist (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget e))))
      (foreach x ptlist (setq sum (mapcar '+ x sum)))
      (setq o (vlax-ename->vla-object e))
      (setq id	     (if bitversion
		       (vlax-invoke-method
			 (vla-get-utility (vla-get-activedocument (vlax-get-acad-object)))
			 'getobjectidstring
			 o
			 :vlax-false
		       )
		       (itoa (vla-get-objectid o))
		     )
	    strfield (strcat "%<\\AcObjProp Object(%<\\_ObjId "
			     id
			     ">%).Area \\f \"%lu2%pr0%ps[, m²]%ds44\">%"
		     )
	    txt	     (vla-addmtext
		       acsp
		       (setq p (vlax-3d-point (mapcar '/ sum (list verts verts))))
		       0
		       strfield
		     )
      )
      (vla-put-attachmentpoint txt acattachmentpointmiddlecenter)
      (vla-put-insertionpoint txt p)
      ;; Make the hatch
      (command "_.-HATCH" "_P" "SOLID" "_S" e "" "")
      ;; Set the hatch to variable 'h'
      (setq h (entlast))
      ;; Get the area of the polyline
      (setq ar (vla-get-area o))
      ;; Define a color based off of area. To get the number for your colors use: (acad_truecolordlg 1)
      ;; Pick your color and see what it returns.
      (setq clr	(cond ;; Area is <= 50 set color to gray
		      ((<= ar 50) '((62 . 8) (420 . 8421504)))
		      ;; Area is <= 100 set color to red
		      ((<= ar 100) '((62 . 1) (420 . 16711680)))
		      ;; Area is <= 150 set color to green
		      ((<= ar 150) '((62 . 3) (420 . 65280)))
		      ;; Area is between 185 and 190 or between 301 and 351 set it to your color
		      ((or (< 185 ar 190) (< 301 ar 351)) '((62 . 244) (420 . 11737633)))
		)
      )
      ;; If we have a color set make the hatch that color
      (and clr (entmod (append (entget h) clr)))
      ;; Remove the entity from the selset
      (ssdel e ss)
    )
    (princ "\n0 Objects found:")
  )
  (princ)
)
(vl-load-com)

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...