Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

vla-open & vla-activate question

18 REPLIES 18
Reply
Message 1 of 19
Anonymous
2340 Views, 18 Replies

vla-open & vla-activate question

I have the following code primarily from code posted for me on this forum by Adesu. (His original code had vlax-true and I added the "setq a" and the last line of the code.)

It works great for my original intention. However, I would like to add code beyond the last line to draw or modify objects. It appears that any code beyond the last line is being ignored. Is that what is supposed to happen?

The full code creates a wblock and then opens and activates the new wblock drawing. Because a new drawing is opened and activated, does the lisp stop at that point? Is that why I cannot continue in the newly created & opened drawing?

(if
(= 0 (getvar "SDI"))
(setq a (vla-open (vla-get-documents (vlax-get-acad-object)) ndwg
:vlax-true))
)
(vla-activate a)
18 REPLIES 18
Message 2 of 19
Anonymous
in reply to: Anonymous

As has been discussed numerous times, lisp can only run in the drawing from
which it was loaded. Once that drawing loses focus, the lisp waits until the
drawing regains focus, unless the drawing is closed at which point the lisp
terminates.

wrote in message news:5237568@discussion.autodesk.com...
I have the following code primarily from code posted for me on this forum by
Adesu. (His original code had vlax-true and I added the "setq a" and the
last line of the code.)

It works great for my original intention. However, I would like to add code
beyond the last line to draw or modify objects. It appears that any code
beyond the last line is being ignored. Is that what is supposed to happen?

The full code creates a wblock and then opens and activates the new wblock
drawing. Because a new drawing is opened and activated, does the lisp stop
at that point? Is that why I cannot continue in the newly created & opened
drawing?

(if
(= 0 (getvar "SDI"))
(setq a (vla-open (vla-get-documents (vlax-get-acad-object)) ndwg
:vlax-true))
)
(vla-activate a)
Message 3 of 19
Anonymous
in reply to: Anonymous

Thank you, Jeff. I know that I had seen several posts previously that lisp loses focus as you reminded me. I didn't know whether it applied to the Visual Lisp. I thought the vl-activate code would give focus to that drawing and allow the lisp to continue. I see, as you stated, that the code continues in the original drawing, when it regains focus. Thank you for confirming what I suspected was the problem, even tho I had hoped that Visual Lisp handled the situation differently than standard AutoLisp.
Message 4 of 19
Anonymous
in reply to: Anonymous

You're welcome. To continue with what you want to do.....if you are just
adding/modifying entities or collections without any user interaction then
you can still use vlisp, just don't activate the drawing. Or, better yet,
use ObjectDBX.

Jeff


wrote in message news:5237685@discussion.autodesk.com...
Thank you, Jeff. I know that I had seen several posts previously that lisp
loses focus as you reminded me. I didn't know whether it applied to the
Visual Lisp. I thought the vl-activate code would give focus to that
drawing and allow the lisp to continue. I see, as you stated, that the code
continues in the original drawing, when it regains focus. Thank you for
confirming what I suspected was the problem, even tho I had hoped that
Visual Lisp handled the situation differently than standard AutoLisp.
Message 5 of 19
Anonymous
in reply to: Anonymous

Thanks for the additional help, Jeff. I'll leave the ObjectDBX to wizards like yourself, tho. I struggle with standard AutoLisp and am just beginning to see the usefullness of Visual Lisp.

I'm curious, tho, what kinds of instruction have wizards like yourself and so many of the others on this forum come from. Do you have college programming courses under your belts, or are there 2 year CAD schools out there that give you guys a leg up with this type of programming? Or just personal study?

I'd love to be able to do what a lot of you guys can do, but my self study and usage sure aren't getting me there any time soon.

THANKS, AGAIN !!!
Message 6 of 19
Anonymous
in reply to: Anonymous

Heh, the only school I've attended for this stuff is TheSchoolOfHardKnocks,
or as you put it "personal study". It just takes time, perseverence, and a
willingness to learn. Oh, and a LOT of reading and trial & error. 😉 And
the reading of which is speak is not necessarily books.....I have not read
one printed book other than what comes with Autocad (well, printed material
used to ship with it...). I did utilize The Visual Lisp Developer's Bible by
David M. Stein, but all other reading was just in any forum/newsgroup I
could find that dealt with lisp. AfraLisp.net has some excellent information
for those just starting out, as well as for those more advanced.

Back to your original post, though.......what is it you want to do with the
Wblocked drawing? Is it something that you can do in the current drawing
BEFORE wblocking it? Maybe set an Undo mark, add/change whatever you need
to, Wblock, Undo End, Undo back?

If you truly want to learn this, there are a lot of us that frequent here
and are quite willing to help you along.

Jeff

wrote in message news:5237727@discussion.autodesk.com...
Thanks for the additional help, Jeff. I'll leave the ObjectDBX to wizards
like yourself, tho. I struggle with standard AutoLisp and am just beginning
to see the usefullness of Visual Lisp.

I'm curious, tho, what kinds of instruction have wizards like yourself and
so many of the others on this forum come from. Do you have college
programming courses under your belts, or are there 2 year CAD schools out
there that give you guys a leg up with this type of programming? Or just
personal study?

I'd love to be able to do what a lot of you guys can do, but my self study
and usage sure aren't getting me there any time soon.

THANKS, AGAIN !!!
Message 7 of 19
Anonymous
in reply to: Anonymous

"BORN GENIUS", was all you needed to say, then. ... Doesn't apply to me, but I'll keep at it.

I think I know how to accomplish what I need by writing and calling a temporary (on-the-fly) script file from within the original lisp file. I believe the script file contents will allow me to open the drawing and run another set of commands or another lisp on the newly opened drawing. I've used something similar before, I think. I would have preferred an approach which didn't require jumping from one file type to another and adding a second lisp, etc., etc., but it'll get my job done, I think.

Never thought of your suggestion to use undo in the original drawing after completing some of what I intended to do in the wblocked drawing. I'll have to consider that approach, as well.

THANKS, "BORN GENIUS" !!
Message 8 of 19
Anonymous
in reply to: Anonymous

Jeff,

I'm interested in your suggestion but I don't see how to add/modify entities if the new drawing isn't active. I've been able to open, save and close a drawing without making it active but any work between open and save is done in the current drawing. How for example would I select the block "TEST" in the new drawing?

S
Message 9 of 19
Anonymous
in reply to: Anonymous

To work in a drawing that is not the active one you have to use ActiveX controls. For example to select all the blocks named "TEST", you would step through each layout and make a list of all the blocks, as making a selection set in a non-active drawing is not available to Lisp.
Message 10 of 19
Anonymous
in reply to: Anonymous

Tim,

ActiveX, eh? My favourite! I've had a play, but I'm stumped...

(setq ISS_blocks (vla-get-Blocks ISS_drawingObj))
(vlax-for Item ISS_blocks
(setq name (vla-get-name item))
(if (= 0 (vl-string-search "*U" name))
(progn
(setq atts (vla-GetConstantAttributes item))
;(vlax-dump-Object item T)
)
)
)

I'm using (vla-GetConstantAttributes item)) to find information about one of my anonymous blocks, but I get "unknown name: GetConstantAttributes" – I guess that item is the block ref rather than the entity... Once I find the anon block that I'm after I then hope to change a text item within the block from "TEXT1" to "TEXT2", rename a layer and then, update the block.

You couldn't give me a few pointers could you?

S
Message 11 of 19
Anonymous
in reply to: Anonymous

The reason why that doesn't work is because the block definition doesn't have a method for GetConstantAttributes. You would have to step through the block definition and find the attribute you are looking for. Something like

(vlax-for blk (vla-get-Blocks Doc)
(if (equal 0 (vl-string-search "*U" (vla-get-Name blk)))
(vlax-for obj blk
(if (= (vla-get-ObjectName ojb) "AcDbAttributeDefinition")
... do your stuff here.. check to make sure it is constant, which I don't know off hand ...
)
)
)
)

Hope that helps.
Message 12 of 19
Anonymous
in reply to: Anonymous

Thanks, Tim. But...

(vlax-for obj blk
(if (= (vla-get-ObjectName ojb) "AcDbAttributeDefinition")
(princ "."))); < test ;

returns "error: bad argument type: VLA-OBJECT nil".

Any clues...?

S
Message 13 of 19
Anonymous
in reply to: Anonymous

Look at the 'if' line.


Hint: Typo. (sorry as it was mine)
Message 14 of 19
Anonymous
in reply to: Anonymous

I knew that!

Thanks,

S
Message 15 of 19
Anonymous
in reply to: Anonymous

You're welcome Scott.
Message 16 of 19
Anonymous
in reply to: Anonymous

Ok, Tim, just one quickie...

I'm happily plodding though my block entities like a pig in... well, once I've changed my text contents how do I 'refresh' my block?

I promise this is the last one...

S
Message 17 of 19
Anonymous
in reply to: Anonymous

The block should refresh on it's own, but if it is the current drawing, and the text doesn't show that it has changed, then you can use the Regen method of the Document object with the parameter of acActiveViewport, so in code

(vla-Regen ActDoc acActiveViewport)
Message 18 of 19
Anonymous
in reply to: Anonymous

wrote in message news:5839861@discussion.autodesk.com...
The block should refresh on it's own, but if it is the current drawing, and
the text doesn't show that it has changed, then you can use the Regen method
of the Document object with the parameter of acActiveViewport, so in code

(vla-Regen ActDoc acActiveViewport)

if you change an attrib, refreshing the blockref doesn't update the att info
(unfortunately) but you can update the att obj if you want to avoid a total
regen as above...which is overkill just to update the att of course.
:-)
mark
Message 19 of 19
Anonymous
in reply to: Anonymous

Thanks, Mark & Tim,

Now I know where and how to look it works like a charm.

S

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report