Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Searching DWG files for where a block is used?

None of the forums really seemed good for this question. But, I figured the most likely people to also need to do this are folks doing 3D assemblies.

I want to search through a directory of DWG files, to find which of them use a particular block. I can't find a utility for this in my V14 BricsCAD. Does it exist in BricsCAD, or perhaps there is a 3rd party utility?

Thanks for any ideas,
-Joe

«1

Comments

  • Hi Joe,
    You would do that most effectively using lisp or .net, and opening a drawing as "side database" (memory, not full editor).
    That is easy for those that have the "lego parts" already sitting around.
    I'll throw together a lisp for that.

  • I think this will do what you want.
    Command is FINDBLKINDWGS.
    You select a file in the folder you want to look through. It does all files in the folder (not subfolders).
    Then enter block names, comma delim with no spaces, just commas between, like "block1,block2"
    It reports on command line.
    Note that it does nothing while looping through files looking. I do have it report status as it goes but it waits til done to spit out on command line...

    This runs on acad and bcad, so you will see stuff in the code to account for each dbx versioning.

    lsp
    lsp
    FindBlocksMult.lsp
    8K
  • Thank you very much. I intend to use it as a "Find where used" sort of function that is common in programs like SolidWorks. I am somewhat surprised there wasn't already a function like what I needed. I don't think BricsCAD has that sort of functionality, but with custom programs, and the programming skills, anything is possible.

    -Joe

  • I have been trying to use your LISP routine. However, I have been frustrated by the first step, of choosing the directory I want to be searched.

    I think that the 1st time I ran it, it allowed me to browse to the directory I want searched, and pressed the "OPEN" button, and then it prompted me to type the name. I tried pasting the name of the block, but that didn't work. So, I ran the routine again, intending to just type the name. But, then I could not get past the file dialog box.

    Thinking that I needed to somehow reset the LISP variables, I first started a new black drawing, with the same results. Then, I exited and restarted BricsCAD, but again I could not get past the file dialog box. I am however able to choose a DWG file and proceed.

    I see that I must type the full name of the block I am seeking. Pasting from the clipboard interrupts the program. Is there any way to past text as the entry for the file name on the command prompt?

    -Joe

  • Hi Joe,
    My bad. I realized the getstring takes a space as enter, so modified that. Try new one attached.

    lsp
    lsp
    FindBlocksMult.lsp
    8K
  • I just tried the new version. But, the problem is the same. I can browse to a folder and then press "open" without any files highlighted, and nothing happens.

    -Joe

  • @Joe Dunfee said:
    None of the forums really seemed good for this question. But, I figured the most likely people to also need to do this are folks doing 3D assemblies.

    I want to search through a directory of DWG files, to find which of them use a particular block. I can't find a utility for this in my V14 BricsCAD. Does it exist in BricsCAD, or perhaps there is a 3rd party utility?

    Thanks for any ideas,
    -Joe

    That would be nice as a default feature.

    Or a warning if you delete a Block that is still in use.
    Or if you delete that Block in use - ask to replace with another Block.
    Or choose a Block to select all its Instances.

  • @Joe Dunfee
    That is correct, you must pick a file, any file, in the folder you want to search through.
    The file dialog will not close until you do that, unless you hit cancel.
    Sorry the interface is a bit archaic. I agree a file selection dialog is horrible for selecting a folder, its just the lesser of a couple evil choices.

  • OK, now I got it. It works.

    In other applications, I have run into the confusion over being prompted to choose a directory, but having to choose "open" to get that directory, after being careful that no files were selected. Though they don't normally require me to choose a file.

    Since your routine seems to offer the option of searching in a particular dwg file, I had assumed that it wold be incorrect to select a file.

    -Joe

  • Ah, very good!
    Note that my tool does all dwg's in the folder picked.
    We could go many directions from here. In particular, you can ask any question about any data in a drawing.
    Like, List all non-plot layers.
    Lock all viewports.
    Anything that does not require graphical manipulation, like "select item at this coordinate and erase"...that needs the editor.
    This is all lisp. You can do even more by same techniques in .net, which is what my file batcher (purgeids tool) does.
    Just fishing for people to be inspired by lisp :)

  • James:

    I was reading about LISP today when this thread appeared.

    What programming environment did you use to write the code?

    I'm a professional software developer with zero LISP exposure. I want to start creating drawing objects by just specifying parameters and have the routine create the gadget for me. I'm on Linux exclusively.

    Any books, web sites, etc to supply information would be helpful.

  • @RoatanBill
    I actually used the VLIDE of Autocad. Yes, I never tested the code in bricscad, the two are so clone perfect that you don't need to.
    Now, if you only have bricscad, use the BLADE environment. Open bcad and type BLADE to open.
    Look up afralisp.com to start learning.
    Some key things to get started in lisp:
    1) use VLIDE or BLADE to edit and test code. They color code things, and allow the oh-so-critical "match braces" function, which is a double click before an open paren, or after a closing paren. That will highlight the enclosed statement and show you if you added too many )'s or too few.
    2) indent code without compromise. Look at the routine I posted as an example. Keep things compact though.
    3) both environments let you select a statement and run to see the results. When learning, you commonly need to test things like (cons "123" somevar) to see what it spits out. You can do that in the middle of running too, to fix a statement you had wrong, like (substr "12345" 2 2). You fix the code to get correct return, then cancel the overall running of your prog, reload code, and rerun. This ability to tweak during runtime and test is amazingly helpful.
    4) lisp statements return one value. That value can be a list, so for subroutines that you want multiple things out of, make them a list and return the list. Once you realize LISP is a bunch of throwing lists around, its becomes much simpler. Avoid global vars to pass info around. They are only for defaults like what I did for folder name and block names in the code. Use a : in the var name to indicate its global.

  • James:

    Thanks for the information. I didn't know BLADE existed so I'll have to research that. I'm hoping BricsCAD has some tutorials on LISP development.

    I looked at afralisp.com and all I get are links to sites that want to sell services or route me to ebay. What am I supposed to see at that site? The domain appears to be for sale.

  • @RoatanBill said:
    I looked at afralisp.com and all I get are links to sites that want to sell services or route me to ebay. What am I supposed to see at that site? The domain appears to be for sale.

    I ran into the same, then found it at www.afralisp.net

    Thanks @James Maeding for all the great ideas to learn.

  • ScottS:

    Why didn't I think of that?

    Thanks.

  • @James Maeding said:
    @Joe Dunfee
    That is correct, you must pick a file, any file, in the folder you want to search through.
    The file dialog will not close until you do that, unless you hit cancel.
    Sorry the interface is a bit archaic. I agree a file selection dialog is horrible for selecting a folder, its just the lesser of a couple evil choices.

    BricsCAD LISP has started to include DOSlib functions. You could use dos_getdir instead of getfiled. However, It does look like this was added from V15 on though. Recommend you take a look at the HELP included in the LDSP.

    BricsCAD V13 Pro users and above do have the option of running DOSlib.

    Regards,
    Jason Bourhill
    BricsCAD V20 Ultimate
    CAD Concepts

  • @RoatanBill
    Lispers hang out at theswamp.org, here some, and the autodesk customization discussion group.
    There are tons of examples on the adesk customization group, and is where most of us came from, likely all of us.

  • James:

    Thanks for the additional sources.

    So far, LISP has to be the ugliest syntactical language I've ever run across and I've code in 22 computer languages. Trying to read someone else's code at this stage is not a learning experience since I get hung up on the crazy syntax.

    I'm going to start writing some LISP routines outside of CAD just to get comfortable with the language syntax. I installed CLISP just to play around with it.

  • @RoatanBill
    I get what you mean, and the reverse polish bugs me some, but I find once I reformat others code some, by removing too many returns, and getting the indentation consistent, its not bad.
    I work with Torsten on the BLADE interface, and its not quite as easy as the VLIDE to use. Its much more powerful in areas, then less in others, some critical. I do lisp projects that have 120 code files involved, so the VLIDE has nice things for "find this word in this project's files" type searches.
    Also, you can load multiple projects at once, which you are likely just doing one lisp file at a time so don't care.
    Once you get comfortable with double clicking to see where a statement ends, the reading is easier.
    Counting parens by hand is insane, don't do that. Also, in blade, you can select a statement, and right click, then run in console to see the return.
    I much prefer visual studio, but then you have to start acad/bcad new each time you want to test anything. The vlide/blade stay open with one session and you can edit and continue type thing.

  • Dear James,

    so the VLIDE has nice things for "find this word in this project's files" type searches ...

    such search is also there in BLADE's "Find/Replace" dialog, also in the "Find References / References tabs," searches across all open + attached project files :-)
    Just in case you overlooked :-)

    many greetings !

  • @RoatanBill said:
    .... LISP has to be the ugliest syntactical language I've ever run across and I've code in 22 computer languages.

    Amen to that. But why not use one of the other languages Bricscad supports?

    I had no choice. When I started out, lisp was the only way to customize Autocad. And using it as-is would be even worse than coding in lisp.

    Bricsys maintains a nice developer's reference at:
    https://www.bricsys.com/bricscad/help/en_AU/CurVer/DevRef/index.html

  • @Anthony Apostolaros

    I'd love to use C or C++ but my reading of the support under Linux suggested that my only option for FULL support was Lisp. I haven't touched a Windows box since 1999; I'm strictly Linux.

    If my interpretation of what I read is incorrect, please advise.

  • I didn't know that. It stands to reason, though. They probably don't sell many Linux seats, since Autocad never made a Linux version.

    So you're probably stuck with Lisp too, at least for now. But at least you're not stuck with Windows. I would have switched to Linux long ago if not for Autocad.

  • @Anthony Apostolaros

    Since you brought it up, I've reconsidered Lisp and may try BRX with C just as an experiment to see what it's like and how far I can get. At least that way I'm in a comfort zone as far as the language is concerned. With Lisp, I'd be battling the language as well as the BricsCAD API set.

  • They're probably adding more Linux support all the time. I've always found Bricsys to be a very helpful, user-friendly organization. That's another point in your favor -- you're not stuck with Autodesk. I was, until Bricscad came along, because I share files with Autocad users, who are a very stubborn and intolerant people.

  • I take it .net is not an option because no visual studio for linux. I'm sure you could compile other ways - well, maybe not if .net frameworks are not on linux. Anyway, if you are going to C to try to avoid lisp, you are headed for disappointment IMO. If you can deal with the C syntax, lisp should be easy, almost boring. Reality is you need to learn both if you are doing heavy stuff with the brx api.
    If you were on windows, this discussion would be over. You use free VS and .net api, and get the best of both worlds as its very similar to the C syntax. You get managed memory though and lots of nice things in .net, plus tons of examples. I would argue better support from bricsys too, as its easier to debug and test .net. By staying linux, you are kind of your own worst enemy in the cad world.

  • Long ago I figured I would avoid trying to learn LISP, thinking that other languages would be a better investment of my time. Other languages can be used in other programs. I thought VBA was the way to go, but that has not proven to be the best choice. Probably C is the smartest choice. LISP is pretty much limited to just AutoCAD and its clones.

    I think the main drawback to C for BricsCAD is that there aren't as many tutorials and books designed to guide you into using it with BricsCAD.

    -Joe

  • Joe, did you request the BRX software developer's kit?

  • @Joe Dunfee
    You need to know both. The startup of acad/bcad is by lisp, and also certain customization like key-ins (.pgp file only goes so far).
    Autolisp is not hard if you get into it. The vars are not typed so you can define them inline which makes for compact code.
    There are patterns to get used to, like building lists with cons or append. Its actually a simple language, you just have to be organized with parens to group code and make it readable.

  • @Anthony Apostolaros said:
    Joe, did you request the BRX software developer's kit?

    No I haven't. I had assumed that this is primarily designed for those who will put apps on the BricsCAD on-line catalog. I am on v14, and don't recall what was available then. I know the L.I.S.P "Lost in Stupid Parentheses" was a problem I ran into, that a proper development package would have solved.

    I just checked and see that the LISP programming utility is part of the BLADE utility that became available with v18. So, that is another reason to upgrade.

    -joe

Sign In or Register to comment.
Origami
Origami is the Japanese word for paper folding. ORI means to fold and KAMI means paper and involves the creation of paper forms usually entirely by folding.

Powered by VanillaForums, Designed by Steam