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

Block Log

62 REPLIES 62
Reply
Message 1 of 63
David_Prontnicki
825 Views, 62 Replies

Block Log

Hey guys not sure if this is possible but I was wondering if there was a way to write a LISP that would "log" the use of a block when inserted into a drawing. We currently have a bunch of dynamic blocks that are really good time savers and we want to track the use of them, to be sure everyone is using them. Looking for something that would list the block inserted, who inserted it, when (date and time), and possibly which drawing. I have written log files to track if a "lisp" is used but never anything like this. Your help is greatly appreciated.

Thank you in Advance,

Dave
62 REPLIES 62
Message 41 of 63

That was it, I changed the block name to *U3 and it created the "Block.log" file but there was nothing in it. It was a blank text file.

I think we are getting there!! LOL 🙂

Dave
Message 42 of 63
Anonymous
in reply to: David_Prontnicki

good lord, that friggin block name was the issue. I was really confused and this post keeps getting bigger and bigger. haha.

Ok Yes we are getting somewhere, I need some time to figure this out, you don't want the block log to say *U3 you will want the block log to notify you of the actual block. The block your inserting is different from what I'm used to using. We will have to change a few things. so gimme a bit to figure out some crap. 😄
Message 43 of 63
Anonymous
in reply to: David_Prontnicki

I have to apologize I completely misread your original post, in wich you Said DYNAMIC BLOCK
Sincerest apologies. 😄

Getting back to work on this momentarily.
Message 44 of 63

I know, if it wasn't so funny I'd be annoyed! LOL I will find out why the blocks are named that way. It may be important for me to stress that these are dynamic blocks so that may be the issue with the block names.

I know I love that feeling of finally getting somewhere, where you know you almost have it. LOL 🙂

Take your time with this, I am leaving tomorrow for a week long vacation so there is no rush at all. And again I cant stress enough how grateful I am for this. Thank you very much for all your help and patience. If by any chance you live in Jersey I'll take you for some beers!! LOL 🙂

Dave
Message 45 of 63
Anonymous
in reply to: David_Prontnicki

If the block is dynamic, or not, you can use the property ' EffectiveName ', and you will get the original block name.

(vla-get-EffectiveName (vlax-ename->vla-object BlockEname))
Message 46 of 63
Anonymous
in reply to: David_Prontnicki

Sadly nowhere Near Jersey : (

This should do the trick.
{code}
(defun justappended ( react objlist / ent entdata logfile object )
(vl-load-com)
(if
(and
(setq ent (cadr objlist))
(setq entdata (entget ent))
(setq object (vlax-ename->vla-object ent)))
(wcmatch (cdr (assoc 0 entdata)) "*INSERT*")
(member (strcase (vlax-get object 'EffectiveName) ) ( list "BLK-STM-MH-DYN" ))
);a
(progn
(setq logfile ( open "H:\\Cad Dept Software\\Logs\\Block.log" "a" ))
(write-line ( strcat "Block: \"" (vlax-get object 'EffectiveName) "\" has been inserted by: " (getvar "loginname") " -- Drawing name: " (getvar "dwgname") " -- Date&Time: " ( MENUCMD "M=$(EDTIME,$(getvar,date),MO/DD/YY HH:MM:SS)" ) ) logfile)
(close logfile)
(vlax-release-object object)
);p
)
)
(if glb-reactor-my-append
(progn
(if (not (vlr-added-p glb-reactor-my-append))
(setq glb-reactor-my-append (vlr-acdb-reactor "testinginserts" '((:vlr-objectappended . justappended))))
);i
);p
(setq glb-reactor-my-append (vlr-acdb-reactor "testinginserts" '((:vlr-objectappended . justappended))))
)
{code}

Probably not the best place to use ( vl-load-com ) but I don't know if you already have it loaded on your computer.
Message 47 of 63
Anonymous
in reply to: David_Prontnicki

Thanks T.Willey,
You were too late, And you made me have to to look that up. 😛
Message 48 of 63

Ok its Working sort of, LOL! 🙂

I first tried it by pasting it into my acaddoc.lsp and nothing happened. ( I will try playing with that) So then I went back to the original acaddoc.lsp and tried just pasting into the command line. That worked!!! The log was created and it listed all the information. The only problem is you get this:

; error: ActiveX Server returned the error: unknown name: "EFFECTIVENAME"

Over and Over again at the command line for as far as I can go back through the text window.

Dave
Message 49 of 63
Anonymous
in reply to: David_Prontnicki

hmmmm, Is it putting the block name in the log, and is it only doing so when you insert that specific block?

That's the way I'm grabbing the block name, so if its returning the block name then that is strange.
Message 50 of 63
Anonymous
in reply to: David_Prontnicki

Lets try it with T.Willeys snippet. Hope this works on 2006 dunno.
{code}
(defun justappended ( react objlist / ent entdata logfile )
(vl-load-com)
(if
(and
(setq ent (cadr objlist))
(setq entdata (entget ent))
( setq object (vlax-ename->vla-object ent )))
(wcmatch (cdr (assoc 0 entdata)) "*INSERT*" )
(member (strcase (vla-get-EffectiveName object) ) ( list "BLK-STM-MH-DYN" ))
);a
(progn
(setq logfile ( open "H:\\Cad Dept Software\\Logs\\Block.log" "a" ))
(write-line ( strcat "Block: \"" (vla-get-EffectiveName object) "\" has been inserted by: " (getvar "loginname") " -- Drawing name: " (getvar "dwgname") " -- Date&Time: " ( MENUCMD "M=$(EDTIME,$(getvar,date),MO/DD/YY HH:MM:SS)" ) ) logfile)
(close logfile)
(vlax-release-object object)
);p
)
)
(if glb-reactor-my-append
(progn
(if (not (vlr-added-p glb-reactor-my-append))
(setq glb-reactor-my-append (vlr-acdb-reactor "testinginserts" '((:vlr-objectappended . justappended))))
);i
);p
(setq glb-reactor-my-append (vlr-acdb-reactor "testinginserts" '((:vlr-objectappended . justappended))))
)
{code}
Message 51 of 63

Ok so I got it to work through the acaddoc.lsp. It had an extra right paran between:

(close logfile)
(vlax-release-object object)
);p
)
) This one
(if glb-reactor-my-append
(progn

It is putting the block name in the log and but here's the kicker, it works for ANY block. When you open a new drawing it even logs the acad zz block that is inserted automaticlly by autocad.
Message 52 of 63

Same thing with T.Willy's!
Message 53 of 63
Anonymous
in reply to: David_Prontnicki

Yeah too many parenthesis.. but not that one. leave it there.

the bad one is near the top

{code}

(and
(setq ent (cadr objlist))
(setq entdata (entget ent))
(setq object (vlax-ename->vla-object ent ))); <--- ******remove one here!!*****
(wcmatch (cdr (assoc 0 entdata)) "*INSERT*" )
(member (strcase (vla-get-EffectiveName object) ) ( list "BLK-STM-MH-DYN" ))
);a

{code}


So. with that fixed. there is still the problem that you mentioned with using *EffectiveName* and I have no idea why. I think it may be the object variable I'm using. if that has any issues I get the same error.
I have one more alternate way that might work but still its a guess.

Edited by: balisteor on Sep 17, 2009 5:05 PM
Message 54 of 63
Anonymous
in reply to: David_Prontnicki

Weeee this is fun. I have to keep pasting the whole thing so nothing gets messed up.



{code}
(defun justappended ( react objlist / ent entdata logfile blockname)
(vl-load-com)
(if
(and
(setq ent (cadr objlist))
(setq entdata (entget ent))
(setq blockname (vlax-get-property (vlax-ename->vla-object ent) "EffectiveName"))
(wcmatch (cdr (assoc 0 entdata)) "*INSERT*" )
(member (strcase blockname ) ( list "BLK-STM-MH-DYN" ))
);a
(progn
(setq logfile ( open "H:\\Cad Dept Software\\Logs\\Block.log" "a" ))
(write-line ( strcat "Block: \"" blockname "\" has been inserted by: " (getvar "loginname") " -- Drawing name: " (getvar "dwgname") " -- Date&Time: " ( MENUCMD "M=$(EDTIME,$(getvar,date),MO/DD/YY HH:MM:SS)" ) ) logfile)
(close logfile)
);p
)
)
(if glb-reactor-my-append
(progn
(if (not (vlr-added-p glb-reactor-my-append))
(setq glb-reactor-my-append (vlr-acdb-reactor "testinginserts" '((:vlr-objectappended . justappended))))
);i
);p
(setq glb-reactor-my-append (vlr-acdb-reactor "testinginserts" '((:vlr-objectappended . justappended))))
)
{code}


I don't know a lot about vla-objects.
Before I was having the program release the object. And maybe that shouldn't be there.
Message 55 of 63

Ok so its working sortof still, 🙂

Now it is only logging the block that is listed with in the list function not all/any blocks. So we are even closer! LOL 🙂

but I am still getting this error everytime I insert:

; error: ActiveX Server returned the error: unknown name: EffectiveName
; error: ActiveX Server returned the error: unknown name: EffectiveName
; error: ActiveX Server returned the error: unknown name: EffectiveName
; error: ActiveX Server returned the error: unknown name: EffectiveName

And again it is there at least a hundred times for each insert. I also get this at start up:

...

Initializing...bad argument type: lselsetp nil
AutoCAD menu utilities loaded._.toolbar DWGGATEWAY.DWGgateway _show

Loading AecCivilBase...
Loading AecDraft...
Loading AecLS...
Loading AecCivilApp...

Initializing...


AutoCAD menu utilities loaded.
Loading retired macros...; error: ActiveX Server returned the error: unknown
name: EffectiveName
; error: ActiveX Server returned the error: unknown name: EffectiveName
; error: ActiveX Server returned the error: unknown name: EffectiveName
; error: ActiveX Server returned the error: unknown name: EffectiveName
; error: ActiveX Server returned the error: unknown name: EffectiveName

Command: AECCSTARTUP

Command: COMMANDLINE

Command:
Message 56 of 63
Anonymous
in reply to: David_Prontnicki

It keeps firing most likely because you probably have a million reactors set.

It looks as if you have defined that function elsewhere in a startup lisp like acaddoc.lsp or something.

Try to remove any programs you have added in that file until we get this one working just stick with pasting it in for now. And use the latest one I've posted.

Plus if you haven't started a completely new Autocad Session recently then type (vlr-remove-all) to be clear of any reactors
Message 57 of 63

Ok so there is nothing in my acaddoc.lsp file and I start a new session, type in (vlr-remove-all), and get a return of nil. Indicating that there are no reactors loaded. I then paste the latest code you sent into the command line and insert the appropriate block. and I still get the same error. But it does log the block beautifully!!! 🙂

The error is the only issue now.

Dave
Message 58 of 63
Anonymous
in reply to: David_Prontnicki

Ok sweet, now can you attach or paste the latest lines in the log for me please.
Danke. 😄



I now see what the problem is. lol Ive said it before but I have to say again.
I'm still learning about vla-objects haha
Message 59 of 63
Anonymous
in reply to: David_Prontnicki

Alrighty .. Scrap the appended and back to the Command reactor. Most of this mess was just trying out new things before it even worked.



K this should be it then I quit... Kidding.
{code}
(defun obj-inserted ( react type / ent logfile blockname)
(vl-load-com)
(if
(and
( setq ent ( entlast ))
( setq blockname (vlax-get-property (vlax-ename->vla-object ent) "EffectiveName"))
(wcmatch ( car type ) "*INSERT*" )
(member (strcase blockname ) ( list "BLK-STM-MH-DYN" ))
);a
(progn
(setq logfile ( open "H:\\Cad Dept Software\\Logs\\Block.log" "a" ))
(write-line ( strcat "Block: \"" blockname "\" has been inserted by: " (getvar "loginname") " -- Drawing name: " (getvar "dwgname") " -- Date&Time: " ( MENUCMD "M=$(EDTIME,$(getvar,date),MO/DD/YY HH:MM:SS)" ) ) logfile)
(close logfile)
);p
)
)
( if global_insert_blocklogreactor
( progn
( if ( not ( vlr-added-p global_insert_blocklogreactor ))
( setq global_insert_blocklogreactor ( vlr-command-reactor nil '((:vlr-commandEnded . obj-inserted ))))
);i
);p
( setq global_insert_blocklogreactor ( vlr-command-reactor nil '((:vlr-commandEnded . obj-inserted ))))
)
{code}
Message 60 of 63

Hats It Man!!!!! Works Like A Dream!!!!!!

Loads from the acaddoc.lsp file with no errors and no errors when inserted!!!!

THANK YOU SO MUCH!!!!!

You have no idea how much I appreciate this!! I will now leave you alone! 🙂

Thanks again, Have a great weekend!!!!

Dave

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