Jump to content

altitude by color - hypsomtric gradient


teknomatika

Recommended Posts

I found an interesting routine that allows coloring 3Dfaces a survey, according to altitude.

By chance, someone knows a similar routine but which takes into account the contours/curves?

 

(See image with the results of routine indicated)

cadtutor_exp2.jpg

Link to comment
Share on other sites

  • Replies 20
  • Created
  • Last Reply

Top Posters In This Topic

  • teknomatika

    9

  • Lee Mac

    4

  • irneb

    4

  • BIGAL

    2

Top Posters In This Topic

Posted Images

Lee, LWPolylines with elevation.
Then the idea is to obtain each LWPoly's elevation Z value: Various ways, but IMO simplest way would be to use entget to extract the PL's DXF codes, then use assoc with code 38 on that.

 

Then you'll need to figure out how the colours are to be varying from level to level:

 

  1. What are the lowest & highest?
  2. How will the colours change between these?
  3. Are there certain levels where a new algorithm for the colour becomes effective?
  4. Will you use colour gradients - i.e. RGB colours instead of ACI?

After that you modify the DXF data list (using entmod) adding the ACI colour to code 62, or the RGB colour to 420.

Link to comment
Share on other sites

Something like this has been asked before here. Take your max min then divide by a step size this gives increment of colour if you use the simple by color approach colours 10-250 then its pretty easy to work out a colour number for the object. RGB is better shades but a bit harder to work out.

Link to comment
Share on other sites

Then the idea is to obtain each LWPoly's elevation Z value: Various ways, but IMO simplest way would be to use entget to extract the PL's DXF codes, then use assoc with code 38 on that.

 

Then you'll need to figure out how the colours are to be varying from level to level:

 

  1. What are the lowest & highest?
  2. How will the colours change between these?
  3. Are there certain levels where a new algorithm for the colour becomes effective?
  4. Will you use colour gradients - i.e. RGB colours instead of ACI?

After that you modify the DXF data list (using entmod) adding the ACI colour to code 62, or the RGB colour to 420.

 

Yes, I believe the solution is to get the z value of each lwpolylinha and assign that value a color gradient, eventually leaving a light tone to the lowest values ​​for a dark tone to the highest values​​.

Following the example of the routine that I mentioned, it would be great to have options for various color palettes.

Eventually, there may be an option to set intervals between the maximum and minimum Z Z, where each interval would apply one color.

Link to comment
Share on other sites

Here's an extremely simplistic version just using ACI colour numbers starting from 10 to 199 - placed from lowest to highest.

(vl-load-com)
(setq *PLColor:ACI_Range* '(10 . 199)
     *PLColor:Z_Range* '(0.0 . 100.0))
(defun PLColour:CalcColour (elevation / z aci)
 (setq z (- (cdr *PLColor:Z_Range*) (car *PLColor:Z_Range*) -1.0)
       z (/ (rem elevation z) z))
 (+ (car *PLColor:ACI_Range*) (fix (* (- (cdr *PLColor:ACI_Range*) (car *PLColor:ACI_Range*)) z))))

(defun c:PLColour (/ ss eList minZ maxZ)
 (if (and (ssget '((0 . "LWPOLYLINE")))
          (setq ss (vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object)))))
   (progn (setq minZ 1.7976931348623158e308 maxZ -1.7976931348623158e308)
     (vlax-for eo ss
       (setq eList (cons eo eList)
             minZ (min (vla-get-Elevation eo) minZ)
             maxZ (max (vla-get-Elevation eo) maxZ)))
     (setq *PLColor:Z_Range* (cons minZ maxZ))
     (foreach eo eList (vla-put-Color eo (PLColour:CalcColour (vla-get-Elevation eo))))
     (vla-Delete ss)))
 (princ))

Link to comment
Share on other sites

irneb, tanks for the help.

 

Unfortunately it seems not to be working. Reports the following error:

; error: An error has occurred inside the *error* functionAutoCAD variable

setting rejected: "cmdecho" nil

 

Also this:

; error: Automation Error. Invalid argument color in IAcadEntity::put_Color

 

Am I doing something wrong?:oops:

Link to comment
Share on other sites

I'm actually having an issue here. On my 2012 it works perfectly fine with those VLA methods, but when I use entmod - nothing happens at all. See if this command-call works on yours:

(defun c:PLColour  (/ ss n ed z eList minZ maxZ)
 (if (setq ss (ssget '((0 . "LWPOLYLINE"))))
   (progn (setq minZ 1.7976931348623158e308
                maxZ -1.7976931348623158e308)
          (repeat (setq n (sslength ss))
            (setq eList (cons (setq ed (entget (ssname ss (setq n (1- n))))) eList)
                  z (cond ((cdr (assoc 38 ed))) (0.0))
                  minZ  (min z minZ)
                  maxZ  (max z maxZ)))
          (setq *PLColor:Z_Range* (cons minZ maxZ))
          (foreach ed eList
            (setq z (cond ((cdr (assoc 38 ed))) (0.0)))
            (entmod (list (assoc -1 ed) (cons 62 (PLColour:CalcColour z)))))))
 (princ))

Just replace the other c:PLColour defun.

Link to comment
Share on other sites

(vl-load-com)
(setq *PLColor:ACI_Range* '(10 . 199)
     *PLColor:Z_Range* '(0.0 . 100.0))
(defun PLColour:CalcColour (elevation / z aci)
 (setq z (- (cdr *PLColor:Z_Range*) (car *PLColor:Z_Range*) -1.0)
       z (/ (rem elevation z) z))
 (+ (car *PLColor:ACI_Range*) (fix (* (- (cdr *PLColor:ACI_Range*) (car *PLColor:ACI_Range*)) z))))


(defun c:PLColour  (/ ss n ed z eList minZ maxZ)
 (if (setq ss (ssget '((0 . "LWPOLYLINE"))))
   (progn (setq minZ 1.7976931348623158e308
                maxZ -1.7976931348623158e308)
          (repeat (setq n (sslength ss))
            (setq eList (cons (setq ed (entget (ssname ss (setq n (1- n))))) eList)
                  z (cond ((cdr (assoc 38 ed))) (0.0))
                  minZ  (min z minZ)
                  maxZ  (max z maxZ)))
          (setq *PLColor:Z_Range* (cons minZ maxZ))
          (foreach ed eList
            (setq z (cond ((cdr (assoc 38 ed))) (0.0)))
            (entmod (list (assoc -1 ed) (cons 62 (PLColour:CalcColour z)))))))
 (princ))

 

Still does not work.

In order to understand better, I attached the file that was being tested.

cadforum_test.dwg

Link to comment
Share on other sites

Maybe:

 

[b][color=BLACK]([/color][/b]defun c:clbyz [b][color=FUCHSIA]([/color][/b]/ ss i en ed vl minz maxz delt ev pc el[b][color=FUCHSIA])[/color][/b]
[b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"LWPOLYLINE"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
    [b][color=NAVY]([/color][/b]setq i [b][color=MAROON]([/color][/b]sslength ss[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
    [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]minusp [b][color=BLUE]([/color][/b]setq i [b][color=RED]([/color][/b]1- i[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
           [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss i[b][color=GREEN])[/color][/b]
                 ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b]
                 vl [b][color=GREEN]([/color][/b]cons [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 38 ed[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] vl[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
    [b][color=NAVY]([/color][/b]setq minz [b][color=MAROON]([/color][/b]apply 'min vl[b][color=MAROON])[/color][/b]
          maxz [b][color=MAROON]([/color][/b]apply 'max vl[b][color=MAROON])[/color][/b]
          delt [b][color=MAROON]([/color][/b]- maxz minz[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
    (not (zerop delt))
    [b][color=NAVY]([/color][/b]setq i [b][color=MAROON]([/color][/b]sslength ss[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
    [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]minusp [b][color=BLUE]([/color][/b]setq i [b][color=RED]([/color][/b]1- i[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
           [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss i[b][color=GREEN])[/color][/b]
                 ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b]
                 ev [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 38 ed[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                 pc [b][color=GREEN]([/color][/b]/ [b][color=BLUE]([/color][/b]- maxz ev[b][color=BLUE])[/color][/b] delt[b][color=GREEN])[/color][/b]
                 cl [b][color=GREEN]([/color][/b]- 250 [b][color=BLUE]([/color][/b]1+ [b][color=RED]([/color][/b]fix [b][color=PURPLE]([/color][/b]* 238 pc[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
           [b][color=MAROON]([/color][/b]entmod [b][color=GREEN]([/color][/b]append ed [b][color=BLUE]([/color][/b]list [b][color=RED]([/color][/b]cons 62 cl[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
           [b][color=MAROON]([/color][/b]princ [b][color=GREEN]([/color][/b]strcat [color=#2f4f4f]"\n"[/color] [b][color=BLUE]([/color][/b]rtos cl 2 0[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
[b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

 

-David

Edited by David Bethel
Link to comment
Share on other sites

David,

tanks for the help.

 

In basic objective works perfectly.

However, in the selection, i would appreciate that in addition to LWPOLYLINES, it was also possible to consider the LINES

Link to comment
Share on other sites

Here is another variation:

[color=GREEN];; Elevation Colour Map  -  Lee Mac[/color]
([color=BLUE]defun[/color] c:emap ( [color=BLUE]/[/color] cmax cmin elv elm enx evl inc lst sel )
   ([color=BLUE]setq[/color] cmin 130
         cmax 170
   )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] sel ([color=BLUE]ssget[/color] [color=MAROON]"_:L"[/color] '((0 . [color=MAROON]"LWPOLYLINE"[/color]))))
       ([color=BLUE]progn[/color]
           ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] inc ([color=BLUE]sslength[/color] sel))
               ([color=BLUE]setq[/color] enx ([color=BLUE]entget[/color] ([color=BLUE]ssname[/color] sel ([color=BLUE]setq[/color] inc ([color=BLUE]1-[/color] inc))))
                     elv ([color=BLUE]cdr[/color]  ([color=BLUE]assoc[/color] 38 enx))
                     lst ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] elv enx) lst)
                     evl ([color=BLUE]cons[/color] elv evl)
               )
           )
           ([color=BLUE]setq[/color] elm ([color=BLUE]apply[/color] '[color=BLUE]min[/color] evl)
                 inc ([color=BLUE]/[/color] ([color=BLUE]-[/color] ([color=BLUE]apply[/color] '[color=BLUE]max[/color] evl) elm) ([color=BLUE]-[/color] cmax cmin))
           )
           ([color=BLUE]foreach[/color] itm lst
               ([color=BLUE]entmod[/color] ([color=BLUE]append[/color] ([color=BLUE]cdr[/color] itm) ([color=BLUE]list[/color] ([color=BLUE]cons[/color] 62 ([color=BLUE]+[/color] cmin ([color=BLUE]fix[/color] ([color=BLUE]/[/color] ([color=BLUE]-[/color] ([color=BLUE]car[/color] itm) elm) inc)))))))
           )
       )
   )
   ([color=BLUE]princ[/color])
)

Specify the colour range at the top of the code (colours must be between 1-255 [inclusive] and cmin cannot equal cmax).

Link to comment
Share on other sites

David,

tanks for the help.

 

In basic objective works perfectly.

However, in the selection, i would appreciate that in addition to LWPOLYLINES, it was also possible to consider the LINES

 

Not without a lot of work. I'd try to PEDIT the lines prior to calling the routine. -David

Link to comment
Share on other sites

Lee, thanks for the help.

It also works perfectly.

 

The option to set the range of colors is equally interesting.

As I said in relation to the code of David, would be also interesting to extend the selection lines.

 

Tanks!

Link to comment
Share on other sites

However, in the selection, i would appreciate that in addition to LWPOLYLINES, it was also possible to consider the LINES

 

Lines are not planar objects and hence do not define an elevation. As David suggests, I would convert any lines to LWPolylines using the PEDIT command with the option to Join lines with coincident endpoints to form continuous planar LWPolylines.

Link to comment
Share on other sites

Lee and David.

 

I appreciate the explanation.

However, your work now matches what I needed.

 

Thank you for your availability and interest shown.

Tanks also to irneb.

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...