Jump to content

Recommended Posts

Posted (edited)

I will really appreciate your help with the following:

I have a drawing with many multileader object with attached block with attributes. The multileader, together with the values of the attributes I can automatically import by constructing "command" lines from excel.


(command "mleader"'(465032.48 6090342.36)'(465034.48 6090345.36)"U13_RB B1_8T" "B1/B2 -0.38m" "B1/B3 0.5m" "B1/B4 0.61m")


Next I would like to change the color of each attribute based on a condition - if number is greater, smaller, between ...


The challenge I have is that I can't reach the attributes directly from the multileader objects.


For the moment I have assembled following code from other scrips I have found on the Internet. It works fine only if I explode the multileader and the blocks are separate objects. I would like to keep the multileader complete and dynamic without exploding all of them.


I have attached one test drawing as well.

(defun truecolor (r g b / tcol)
 (setq tcol (vlax-create-object "AutoCAD.AcCmColor.21"))
 (vla-setRGB tcol r g b)
  tcol
  )

(defun modattcolor(txt r g b up low / tcol )
  (setq txt (strcase txt)
       ;up  (strcase up)
		;low (strcase low)
		)
  (setq tcol (truecolor r g b))

(if
  (ssget "x" '((0 . "insert")(66 . 1)))
  (vlax-for n (vla-get-activeselectionset
		(vla-get-activedocument
		  (vlax-get-acad-object)))
    (foreach m (vlax-invoke n 'getattributes)
      (if (and
				(wcmatch (strcase (vla-get-textstring m)) txt)
	            (or
				( = (< (atof(substr (substr (vla-get-textstring m) 7) 1 (- (strlen (substr (vla-get-textstring m) 7)) 1)))  low) T)
				( = (> (atof(substr (substr (vla-get-textstring m) 7) 1 (- (strlen (substr (vla-get-textstring m) 7)) 1)))  up) T)
			      )
			  )
	(vla-put-truecolor m tcol)
	)
      )
    )
  )
  )
  ;calling the modattcolor function with (tag content) (RGB color) (tag upper-limit) (tag lower-limit )
  (modattcolor "**" 255 0 0 1 0)
  (modattcolor "B1/B2*" 0 0 255 100 10)
  (modattcolor "A1/A2*" 0 0 255 100 10)
  (modattcolor "B1/B2*" 255 0 0 0 -0.5)
  (modattcolor "A1/A2*" 255 0 0 0 -0.5)

Test Tag.dwgFetching info...

image.png

Edited by 4o4osan
Posted

Hi
What number?
And: greater or less than what?

Posted

Can you attach an image as an example?

Posted (edited)

I don't think your mleader is correct need the use a block as a choice. Check manually.

Mleader O C Block bname........

 

Yes can read Excel from CAD so make the mleaders. Or a Macro in Excel will draw the mleader.

Edited by BIGAL
Posted

Hi GLAVCVS,

 

In the code itself I have implemented the check if attribute contents are matching with the criteria.
 

(if (and
				(wcmatch (strcase (vla-get-textstring m)) txt)
	            (or
				( = (< (atof(substr (substr (vla-get-textstring m) 7) 1 (- (strlen (substr (vla-get-textstring m) 7)) 1)))  low) T)
				( = (> (atof(substr (substr (vla-get-textstring m) 7) 1 (- (strlen (substr (vla-get-textstring m) 7)) 1)))  up) T)
			      )
			  )


The function modattcolor is called with those variables as an entry
txt - partial match of the attribute content

r g b - red green blue color index

up - upper limit for the number stripped out of the attribute content

low - lower limit for the number stripped out of the attribute content

(defun modattcolor(txt r g b up low / tcol ) 

 

Posted

Hi BIGAL,

 

I have no real problem with creating the multileader. In fact this is a predefined multileader style with block with attributes as a content.
image.thumb.png.a1d965f66d4186faef8db5506a69d1ae.png

My main challenge is reaching those block attributes and "vla-put-truecolor" to it. Those blocks are nested inside the multileader and can't find a way to select and add to a set suitable for editing :(

 

FYI, I am using BricsCAD V20.

Posted

I don't understand
You say you don't want to exploit the 'MULTILEADER' objects but your code works with 'INSERT' objects
Also, this code doesn't apply to the attached drawing because there are only 'MULTILEADER' objects

In any case, although I don't know these objects very well, I have managed to change the color of the attribute of one of the MULTILEADER objects, but then the same attributes are also changed in the other MULTILEADER objects.
My impression is that it won't be possible to change that color without affecting the rest.

Posted

I think you're going to have no choice but to explode them.

Posted

Hi GLAVCVS,

 

Exploding the multileader is exactly what I am doing and my code from above works perfectly with this scenario by finding blocks and iterate the color change.

 

What I was hoping is to keep the the multileader complete and dynamic (not exploding it) and still be able to change each attribute color based on the value it has.

Posted

If I'm reading your logic correctly you're making sure that the number that is read is within a range? If so this:

(if (and (wcmatch (strcase (vla-get-textstring m)) txt)
	 (or (=	(< (atof (substr (substr (vla-get-textstring m) 7)
				 1
				 (- (strlen (substr (vla-get-textstring m) 7)) 1)
			 )
		   )
		   low
		)
		t
	     )
	     (=	(> (atof (substr (substr (vla-get-textstring m) 7)
				 1
				 (- (strlen (substr (vla-get-textstring m) 7)) 1)
			 )
		   )
		   up
		)
		t
	     )
	 )
    )
  (vla-put-truecolor m tcol)
)

 

Could be this:

(if (and (wcmatch (strcase (vla-get-textstring m)) txt)
	 (not (<= low (atof (substr (vla-get-textstring m) 7)) up))
    )
  (vla-put-truecolor m tcol)
)

 

Posted

Thanks BIGAL,

 

The final sentence in that post made me think of another way of doing it :)
"I thought this was gonna be a simple fix to start with... Obviously blocks nested in mleaders isn't straight forward."

I made a dynamic block with a leader and attributes. This object is much easier to access and modify the properties of the attributes. 

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