Rename visibility

Rename visibility

msarqui
Collaborator Collaborator
1,879 Views
18 Replies
Message 1 of 19

Rename visibility

msarqui
Collaborator
Collaborator

Hi guys,

 

I am wondering... Is it possible to rename the visibility in a dynamic block with lisp?
I am not talking about the visibility parameter, but the visibility that are associate to it. For example, I have a block with 3 visibility: PLAN, PROFILE, ELEVATION.
So, is it possible to rename, for example, PLAN to PROPOSED PLAN and so on?

 

Many Thanks,

Marcelo

0 Likes
1,880 Views
18 Replies
Replies (18)
Message 2 of 19

Ranjit_Singh
Advisor
Advisor

As far as I know, it's not possible.

0 Likes
Message 3 of 19

rapidcad
Collaborator
Collaborator

Hmmm, never thought of that. I wonder if ENTMOD could be used, but you'd have to dig deep into the entity code to come up with access to the list of visibilities. I highly doubt that it can be done with vlisp, but if the real geniuses see this - you never know - I hesitate to say it can't.

ADN CAD Developer/Operator
0 Likes
Message 4 of 19

john.uhden
Mentor
Mentor

I'm still using only AutoCAD 2002, but there is always hope for problems like this.  Just recently I found that you can not (entdel) an attribute within a block insertion, but you can (vla-delete) it.

 

To help myself along I (setq dump vlax-dump-object) so I could more easily see the properties and methods available to whatever into which I run.  I really despise typing.  Plus, maybe I have mild dyphliaxes.

 

Also, sometimes (vlax-invoke object 'method) works, but sometimes only (vla-method) works, and vice versa.  Isaac Newton didn't invent gravity in just one day, ya know.

John F. Uhden

0 Likes
Message 5 of 19

Anonymous
Not applicable

I' ve tried this code, i get visibility states but when i want to change them, entmod function didn't work... i guess i messed up 😛

 

(defun c:renvisible ()
  (vla-StartUndoMark (vla-get-activedocument (vlax-get-acad-object)))
  (setq parameterlist nil)
  (setq obje(entsel "\nSelect a dynamic block"));Get the block
  (while (or (= obje nil) (/= "INSERT" (cdr(assoc 0 (entget (car obje))))) (/= :vlax-true (vla-get-isdynamicblock (vlax-ename->vla-object (car obje)))))
    (setq obje(entsel "\nSelect a valid dynamic block"));
    )
  (setq vsblename1 (getstring "\nPlease write a visibility name to be changed" t))
  (setq vsblename2 (getstring "\nPlease write a visibility  new name to visibility" t))
  (setq blk (vla-get-effectivename (vlax-ename->vla-object (car obje))))
  (Princ (strcat "\nBlock Processsing: " blk "\n"))
  (setq ent (tblobjname "block" blk))
  (setq EVAL_GRAPH(entget(cdr(assoc 360 (entget(cdr (assoc 360(entget (cdr (assoc 330 (entget ent)))))))))))
  (While (/= nil (assoc 360 EVAL_GRAPH))
    (setq parameter (cdr (assoc 360 EVAL_GRAPH)))
    (if (= (cdr (assoc 0 (entget parameter))) "BLOCKVISIBILITYPARAMETER")
      (progn
        (setq parameterlist (entget parameter))
        (setq updateparameter (entget parameter))
        (while (/= nil (assoc 303 parameterlist))
          (setq visibility (cdr (assoc 303 parameterlist)))
          (princ "\n")
          (princ (strcat "\nVisibility State:" visibility))
          (if (wcmatch vsblename1 visibility)
            (progn
              (setq updateparameter (subst (cons 303 vsblename2) (cons 303 vsblename1) updateparameter ))              
              );progn
            );if
          (setq parameterlist(vl-remove (assoc 303 parameterlist) parameterlist))
          );while
        (setq updateparameter (vl-remove (assoc 1071 updateparameter) updateparameter))
        (setq updateparameter (vl-remove (assoc 1010 updateparameter) updateparameter))
        (entmod updateparameter)
       );progn
      );if
    (setq EVAL_GRAPH(vl-remove (assoc 360 EVAL_GRAPH) EVAL_GRAPH))
    )
  (princ)
         
  )
Message 6 of 19

rapidcad
Collaborator
Collaborator

HI Zabidinbostan, as I step through your code on a dynamic block with a visibility parameter, I get as far as your while loop and no further.

I'm finding that your setq EVAL_GRAPH is not finding any 360 group code objects in the list. I'll try to dig in a little bit more but I suspect that you might have arrived at some sort of safearray situation in the structure of visibility parameters, but I could be just displaying my ignorance there. If you could get your while loop to function just one loop, then something is really different about your dynamic block or the method you are using to isolate the visibility parameter. I have not isolated it yet using the function and digging into the elements of the lists.

 

Have you tried stepping through the program by testing it on several different dynamic blocks? Can you get  (/= nil (assoc 360 EVAL_GRAPH)) to evaluate T?

 

HTH, that's about as far as I can help.

ADN CAD Developer/Operator
0 Likes
Message 7 of 19

Anonymous
Not applicable

At the EVAL_GRAPH level, it can be several (360 . x) dotted pairs. Some of them are dynamic parameters such as flip, visibility or distance. With that while loop, if there is an (360 . x ) dotted pair that belongs to visibility parameter than we gain entity name. Code can get visibilty states and lists them... but when i edit the dotted pair that belongs the name (303 . X), i can't use entmod function to update information.

 

(NOTE: entmod function gives an error if i don't remove 1071 and 1010 dotted pairs.)

0 Likes
Message 8 of 19

rapidcad
Collaborator
Collaborator

Ok, my bad. I was testing this on a much more complex dynamic block which uses a block property table to change the visibility.

 

Let the OP know, yes it can be done and you, zabidinbosdan, have done it! Well, it works but it seems to be a bit unreliable. I was able to change the visibility state names in two rather simple dynamic blocks but on others it did not work. I also wonder if part of the problem is whether the visibility is current or not.

 

Congratulations on getting this to work- even if it's unreliable. I love to see what is possible. Now can it be made bulletproof? And one more nicety, it would really help to pop a dialog with a list of visibility state names to select from so that one would not have to recall exactly the name of the state.

 

Way to go!

 

ADN CAD Developer/Operator
0 Likes
Message 9 of 19

msarqui
Collaborator
Collaborator

Hi guys,

 

Thank you all for your help.

 

zabidinbostan, it is not working on my DB. Please, see attached file.
 
 
 
I am working with AutoCAD 2016
0 Likes
Message 10 of 19

Ranjit_Singh
Advisor
Advisor

Just confirmed it is not working on 2015 either. Not even with a simple dynamic block

0 Likes
Message 11 of 19

Anonymous
Not applicable

I' ve said that entmod function didn't work. so code is not working. If anybody can solve entmod function situation, it can work again. Because the code can gain visibilty states from entities. 

0 Likes
Message 12 of 19

Ranjit_Singh
Advisor
Advisor

OK. Understood. I thought it worked based on post 8 of 11


@rapidcad wrote:

................. 

Let the OP know, yes it can be done and you, zabidinbosdan, have done it! ....................................


The only way I see it can be done is open your block editor and change the state names. To make it easier you can automate as far as getting the block editor opened for the user (maybe even opening the visibility state dialog box). I am still certain that there is no visual lisp way where you can simply expose a method to change that visibility name, because such a method does not exist. Using LISP dxf codes is also not a way to go since no documentation exists stating explicity what entmod does and what it does not (at least not for every single graphical/non-graphical entity type)

0 Likes
Message 13 of 19

Ranjit_Singh
Advisor
Advisor

Also visibility states can simply be gained with vlisp as follows

(vlax-get (car (vlax-invoke (vlax-ename->vla-object (car (entsel))) 'getdynamicblockproperties )) 'AllowedValues)

  

But as you can see,

(vlax-dump-object (car (vlax-invoke (vlax-ename->vla-object (car (entsel))) 'getdynamicblockproperties )) T)

 

those values are read-only. That's a pretty good indication that they cannot be changed.

0 Likes
Message 14 of 19

rapidcad
Collaborator
Collaborator

Sorry to not reply earlier - I've been really busy. It does work in AutoCAD 2011, but I see no change in AutoCAD 2016-2017.

 

Here's a screenshot:

Before.JPG

 

...And Afterwards:

After.JPG

 

No harm to the block either!  GREAT JOB! Now to figure out what is the problem with the newer versions...

ADN CAD Developer/Operator
Message 15 of 19

Anonymous
Not applicable

Very interesting, i wrote a code... it doesn't works for me... 🙂 As it seems the code gets along well with you 🙂

 

I will try the code on autocad 2011...

0 Likes
Message 16 of 19

Ranjit_Singh
Advisor
Advisor

@Anonymous I am really curious now. I will also try to run the routine on 2011. Can you please post a screencast when you run. I will do the same.

0 Likes
Message 17 of 19

rapidcad
Collaborator
Collaborator

Hi guys. I've been off a few - still off since having surgery, but I just checked my email and saw this. I can try to post a screencast...

https://www.screencast.com/t/OQC0XnmOkr87

 

HTH

ron

ADN CAD Developer/Operator
0 Likes
Message 18 of 19

msarqui
Collaborator
Collaborator

Hi guys,

 

I did a research in my stuff and I found an old routine that someone did for me that uses entmod to switch the background fill in a multiline attribute. During the tests the routine worked well in AutoCAD 2010 but not in 2012. I did not test in 2011.
I think Autodesk changed something in the code after 2010 or 2011, and entmod has no longer the same "ability".

 

Anyway, many thanks for all to try.
Marcelo 

0 Likes
Message 19 of 19

rapidcad
Collaborator
Collaborator

Marcelo, I don't think ENTMOD changed any, I know that the MLEADER fill and border options did however. I also have a program that sets the background mask and frame on MTEXT that the program first creates using VL-CMD and setting options. My routine had to be changed to check what version of AutoCAD was being used and then apply the correct function.

 

Nothing changed with dynamic block visibilities in the 2010-2017 AutoCAD versions. All I remember is that the UNDO calls have to be different for newer (I think 2013 and above) not containing command calls within them.

 

Although unrelated, here's my chunk of code for the MLEADER version issue:

(initcommandversion 1)

    (vl-cmdf "._mleader" "o" "m" "2" "c" "m" "x" arrwpt	pikpt tagval)
    (setq ent (entlast))
    (vla-put-TextJustify (vlax-ename->vla-object ent) 2)
    (vla-put-LandingGap (vlax-ename->vla-object ent) 0.046875)
    (if	(>= (atof (substr (getvar "acadver") 1 4)) 19.0)
	(vla-put-TextBackgroundFill
	  (vlax-ename->vla-object ent)
	)
      (progn
	(setq ed (entget ent))
	(setq new291 (cons 291 1))	;background color on?
	(setq new292 (cons 292 1))	;background fill on?
	(setq new141 (cons 141 1.1))	;offset for mask
	(setq ed
	       (subst new141
		      (assoc 141 ed)
		      ed
	       )
	)
	(entmod ed)
	(setq ed
	       (subst new291
		      (assoc 291 ed)
		      ed
	       )
	)
	(entmod ed)
	(setq ed
	       (subst new292
		      (assoc 292 ed)
		      ed
	       )
	)
	(entmod ed)

      )
    )

    (vla-put-TextFrameDisplay
      (vlax-ename->vla-object ent)

    )
    (entupd ent)

 

ADN CAD Developer/Operator
0 Likes