LISP table with hatched areas by layer name

LISP table with hatched areas by layer name

karpki
Advocate Advocate
7,921 Views
36 Replies
Message 1 of 37

LISP table with hatched areas by layer name

karpki
Advocate
Advocate

Hi experts

I use a lisp to make the table of hatched areas (attached)

It makes it by the area order from biggest to smallest

How to shange lisp so  table will be made by th Layer name but not by Area ? Any ideas ?

The layer name will contain also figure f/e/ 1.aisles 2.services etc etc to build the correct order in table

0 Likes
Accepted solutions (2)
7,922 Views
36 Replies
Replies (36)
Message 2 of 37

karpki
Advocate
Advocate

Corrected lisp

0 Likes
Message 3 of 37

Sea-Haven
Mentor
Mentor

Its confusing what you want the code was written by Pbe and he submits here often.

 

Just do a dummy table use mtext or notepad etc to show what it is you want

 

layer1   Lines 123

layer1   Circles 45

and so on

0 Likes
Message 4 of 37

karpki
Advocate
Advocate

Well, now I'm confused.

About half year ago someone gave it to me at this forum, probably it was @Pbe and the great respect to him!

Should I ask him directly now ? I was thinking that this is the open society and we discuss everything public... Isn't it ?

Existing tab, needed tab and testing file are attached.

 
 
 
0 Likes
Message 5 of 37

karpki
Advocate
Advocate

For the header (name of the dwg file) I have just added few lines into the code, see attached

Also changed some formats comparing the original code

0 Likes
Message 6 of 37

hak_vz
Advisor
Advisor
Accepted solution

Here it is.

Change naming of your layers, so instead of 1.bbb, 2.mmm, 28.ccc use 01.bbb, 02.mmm, 28.ccc or 001..... if you have more categories.

 

Correction is a simple change of sorting order (basics of autolisp) Maybe it's time to start learning Autolisp.

 

(setq AllData (vl-sort AllData '(lambda (m n) (> (Cadr m) (cadr n)))))
to
(setq AllData (vl-sort AllData '(lambda (m n) (< (Car m) (car n)))))

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 7 of 37

karpki
Advocate
Advocate

You are absolutelly right, just started finding materials and do first exercizes

Thanks for your time!

 

0 Likes
Message 8 of 37

diagodose2009
Collaborator
Collaborator

Please you fix this bugs....

 

Unsorted AllData=((DEAL_0 8.51123e+009) (DEAL_4 2.13383e+008) 
(ORIGINAL_NEGRU_SCRIS_INCLINAT 89678.6) (DEAL_1 1.41233e+009) (DEAL_3 
1.9555e+009) (APELE 1.75762e+006) (DEAL_2 1.60347e+009) (ORIGINAL_NEGRU 
2.13448e+008))
Pick point for Table:; error: bad argument type: consp "Category"

 

0 Likes
Message 9 of 37

karpki
Advocate
Advocate

Tried extra code to set cellbackgroundcolor which should correspond to Layer color but without any success

Could you please look through what's wrong

Sorry in advance if this was totally stupid logic 🙂 I just trying coding

If it helps I have create blocks with the name of Layer to use it, but this way also was unhappy dwg is also attached

The result should be kind of this:

karpki_0-1610479394153.png

 

0 Likes
Message 10 of 37

hak_vz
Advisor
Advisor
Accepted solution

Try this code in attachment.

 


@karpki wrote:

I just trying coding


Start learning autolisp from basics, and not with complex stuff as scripting acad tables.

 

If code won't work try to replace

 

(setq x(strcat "AutoCAD.AcCmColor."  (substr (getvar 'Acadver) 1 2)))
;this is my untested try to grasp correct version

For Acad2015, use AutoCAD.AcCmColor.20 
 - > (setq x "AutoCAD.AcCmColor.20")
For Acad2016/17, use AutoCAD.AcCmColor.21
 - > (setq x "AutoCAD.AcCmColor.21")
For Acad2018, use AutoCAd.AcCmColor.22
 - > (setq x "AutoCAD.AcCmColor.22")
For Acad2019, use AutoCAD.AcCmColor.23
 - > (setq x "AutoCAD.AcCmColor.23")
....

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 11 of 37

karpki
Advocate
Advocate

It works! Perfect

Thank you!

0 Likes
Message 12 of 37

karpki
Advocate
Advocate

If smb needs

3-d column added for colour

karpki_0-1610526992006.png

 

0 Likes
Message 13 of 37

hak_vz
Advisor
Advisor

@karpkiI like it. If you can change the way you show square meters it would be even better. Change m2 in cell format to m\U+00B2  (unicode for squared).

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 14 of 37

karpki
Advocate
Advocate

Good idea!

Thanks!

0 Likes
Message 15 of 37

karpki
Advocate
Advocate

But I guess this is kind of Field function and unicode doesn't work there


 
Обновление медиа

 

0 Likes
Message 16 of 37

hak_vz
Advisor
Advisor

Is it really a must to use a fields.

Here is a function that I use to write area as a decimal number written according ISO standard.

 

    Numbers should be printed in upright (roman) type.
    ISO 31-0 (after Amendment 2) specifies that "the decimal sign is either the comma on the line or the point on the line". This follows resolution 10[1] of the 22nd CGPM, 2003.[2]

    For example, one divided by two (one half) may be written as 0.5 or 0,5.

    Numbers consisting of long sequences of digits can be made more readable by separating them into groups, preferably groups of three, separated by a small space. For this reason, ISO 31-0 specifies that such groups of digits should never be separated by a comma or point, as these are reserved for use as the decimal sign.

    For example, one million (1000000) may be written as 1 000 000.

    For numbers whose magnitude is less than 1, the decimal sign should be preceded by a zero.
    The multiplication sign is either a cross or a half-height dot, though the latter should not be used when the dot is the decimal separator.

 

 

 

 

(defun  razd (num dec_places unit_string / _num dec_places poz _rem frac _r portions n i a b neg)
	(if (< num 0.0) (setq neg "-")(setq neg ""))
	(setq _num (rtos num 2 dec_places) _num (strcat _num "00000000"))
	(if (setq poz(vl-string-position (ascii ".") _num)) (setq _rem (substr _num 1 (+ poz 1)) frac (substr _num (+ poz 2)))(setq frac ""))
	(setq num (abs num ) _r (rem num 1.0) num (- num _r))
	(if (and(> _r  0.5)(eq dec_places 0)) (setq num (+ 1 num)))
	(while (> num 0.0)(setq portions (cons (fix (rem num 1000.0)) portions)num (/ (- num (car portions)) 1000.0)))
	(setq n (length portions) i 0 a "")
	(while (< i n)
		(setq b (rtos (nth i portions) 2 0))
		(if (and (eq (strlen b)1) (> i 0)) (setq b (strcat "00" b)))
		(if (and (eq (strlen b)2) (> i 0)) (setq b (strcat "0" b)))
		(if (< i (- n 1))(setq a (strcat a b " ")) (setq a (strcat a b)))
		(setq i (+ 1  i))
	)
   (if (> dec_places 0 )(setq a (strcat a "," (substr frac 1 dec_places))))
   (strcat neg a " " unit_string "\U+00B2")
)

 

 

 

Command: (razd 32319.576 2 "m")    ->  "32 319,58 m²"
Command: (razd 32319.576 0 "m")    ->  "32 320 m²"

 

 

Or try in your code

 

(vla-setcellformat Area_table crow 1 "%lu2%pr1%ps[, m\U+00B2]%ct8[1.000000000000000E-006]")  

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 17 of 37

karpki
Advocate
Advocate

Thank you for such interesting info and function. I will study it bit by bit and comment later.

To use this unocode in my line was negative. Same reaction like in Field - just print it without transformation to "m²"

0 Likes
Message 18 of 37

karpki
Advocate
Advocate

For those architects who needs it

1/ Have added code to short the name of category . The preficses of the layer name needed for my own aim and for correct order (_01.) are not printing anymore:

 

(setq lname(substr (setq str2 (car d)) 5 (- (strlen str2) 0)))
(vla-setCellValue Area_table crow 0 lname)

 

2/ Have tried to add m² by sentences like \U+00B2 or \\U+00B2 ... few different ways to the line with the sq meters  formatting, no success. So left it without it at all:

 

(vla-setcellformat Area_table crow 1 "%lu2%pr1%ct8[1.000000000000000E-006]")

 

!But today realized that it works in the line printing second row names:

 

(list '(0 "Category") '(1 "Area, m\U+00B2") '(2 "Colour"))

 

So result is quite good from the point of view that m² is much better than m2 to show in documents:

karpki_0-1610819787390.png

 

0 Likes
Message 19 of 37

hak_vz
Advisor
Advisor

@karpki 

 

That's why I posted my code above. This string value representing area is to be shown in the table.

At my side it works perfectly.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 20 of 37

karpki
Advocate
Advocate

I have found quite a simple way to make space separation. The sentence %th32 is added to the end of formatting code so the whole line looks like this:

(vla-setcellformat Area_table crow 1 "%lu2%pr1%ct8[1.000000000000000E-006]%th32")

 

What I'd like to get is how to make colour markers transparent. Tried such code - (vla-setCellBackgroundTransparency Area_table crow 2 50) but it doesn't work. Any ideas ?

 

Current result looks like this:

karpki_0-1611075547531.png

 

0 Likes