ABuckingham Posted June 10, 2009 Share Posted June 10, 2009 I've been tasked with a rather large monotonous job, and was hoping someone could help me out. I need to move objects from one layer to another using some predictable conditions and don't want to spend a couple days doing it, here's the skinny. Given an object, check to see it the layer it's on ends in -E, so for example FOO-BAR-E In a separate template file called TEMP.DWG, check to see if a layer exists with a -N suffix, and if so move import the layer from the template and move the object to that layer, so if FOO-BAR-N is a layer in the template, bring that layer into the current drawing then move the object from FOO-BAR-E to FOO-BAR-E If there is no layer with the -N suffix, check to see if there is a suffix-less layer in the same template file and if so, move it to that layer so FOO-BAR-E to FOO-BAR If both those don't exist, then just move along to the next object. Rinse and repeat for the next 200 drawings. I'm not fussy about VBA or AutoLISP, and I'm working in AutoCad 2008. Any help would be great. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 10, 2009 Share Posted June 10, 2009 Everything seems do-able - but I think it would be better that you could input the layer changes into the LISP prior to running it, instead of using a Template File - switching between drawings in LISP is hard enough as it is... Quote Link to comment Share on other sites More sharing options...
ABuckingham Posted June 11, 2009 Author Share Posted June 11, 2009 Thanks Lee I'll check it out this afternoon when I get back onto that project. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 11, 2009 Share Posted June 11, 2009 The above won't work - I'll remove it and see what else I can come up with Quote Link to comment Share on other sites More sharing options...
ABuckingham Posted June 11, 2009 Author Share Posted June 11, 2009 Thanks Lee I gave it a try and as you said it didn't work. If I wasn't working on learning VBA for Microstation ( ) I'd try to whip something together this weekend but this project isn't as urgent as my others. As always, thanks for your help and contributions to the community here. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 11, 2009 Share Posted June 11, 2009 Try this instead mate: (I'm learning this ObjectDBX stuff, so its a bit hit and miss...) ;; ObjectDBX Tester by Lee McDonnell (Lee Mac) ;; Credit to Tony Tanzillo for Directory Browser, Tim Willey (defun c:MacDwg (/ refLst *error* *acad Shell fDir Dir dbx lay Tag) (vl-load-com) (setq refLst '( ("FOO-BAR-E" . "FOO-BAR-N") ("FOO-CAR-E" . "FOO-CAR-N") ) ) (defun *error* (e) (if ov (mapcar 'setvar vl ov)) (ObjRel (list Shell dbx *acad)) (if (not (wcmatch (strcase e) "*CANCEL*,*EXIT*")) (princ (strcat "\n<< Error: " e " >>"))) (princ)) (setq *acad (vlax-get-acad-object) Shell (vla-getInterfaceObject *acad "Shell.Application") fDir (vlax-invoke-method Shell 'BrowseForFolder (vla-get-HWND *acad) "Select Directory: " 0)) (if fDir (progn (setq Dir (vlax-get-property (vlax-get-property fDir 'Self) 'Path)) (if (not (eq "\\" (substr Dir (strlen Dir)))) (setq Dir (strcat Dir "\\"))) (if (< (atoi (setq acVer (substr (getvar "ACADVER") 1 2))) 16) (setq acVer "") (setq acVer (strcat (chr 46) acVer))) (setq dbx (vla-getInterfaceObject *acad (strcat "ObjectDBX.AxDbDocument" acVer))) (princ "\nProcessing...") (foreach dwg (setq dwLst (mapcar (function (lambda (x) (strcat Dir x))) (vl-directory-files Dir "*.dwg" 1))) (vla-open dbx dwg) (vlax-for Lay (vla-get-layouts dbx) (vlax-for Obj (vla-get-Block lay) (if (setq Tag (assoc (vla-get-layer Obj) refLst)) (vla-put-layer Obj (cdr Tag))))) (vla-saveas dbx dwg) (princ (chr 46))) (princ (strcat "\n<< " (rtos (length dwLst) 2 0) " Drawings Processed >>")))) (ObjRel (list Shell dbx *acad)) (gc) (princ)) (defun ObjRel (lst) (mapcar (function (lambda (x) (if (and (eq (type x) 'VLA-OBJECT) (not (vlax-object-released-p x))) (vl-catch-all-apply 'vlax-release-object (list x))))) lst)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 11, 2009 Share Posted June 11, 2009 If I wasn't working on learning VBA for Microstation ( ) I'd try to whip something together this weekend but this project isn't as urgent as my others. Why are you learning VBA? I thought that was extinct... Quote Link to comment Share on other sites More sharing options...
wannabe Posted June 11, 2009 Share Posted June 11, 2009 Why are you learning VBA? I thought that was extinct... I don't think there is a .NET API for Microstation yet. There wasn't when I last checked earlier in this year. Bentley forums will tell us all. Quote Link to comment Share on other sites More sharing options...
wannabe Posted June 11, 2009 Share Posted June 11, 2009 http://www.la-solutions.co.uk/content/MicroStationDevelopmentLanguages.htm#.NET Here we go. Basically .NET just uses COM interop. Now I remember why I deferred programming some Microstation apps. Quote Link to comment Share on other sites More sharing options...
ABuckingham Posted June 11, 2009 Author Share Posted June 11, 2009 No luck, same error. > Quote Link to comment Share on other sites More sharing options...
Patrick_35 Posted June 12, 2009 Share Posted June 12, 2009 Hi Mac I have just one remark about your lisp about objectdbx If a drawing of the directory is already open, it crashes. One example which I used (defun Ouvrir_dessin_dbx(dwg / dbx doc lan rel) (and (setq dwg (findfile dwg)) (progn (vlax-for doc (vla-get-documents (vlax-get-acad-object)) (and (eq (strcase (vla-get-fullname doc)) (strcase dwg)) (setq dbx doc lan T) ) ) (and (not dbx) (setq dbx (vlax-create-object (if (< (setq rel (atoi (getvar "ACADVER"))) 16) "ObjectDBX.AxDbDocument" (strcat "ObjectDBX.AxDbDocument." (itoa rel)) ) ) ) (vla-open dbx dwg) ) ) ) (list dbx lan) ) An example (Ouvrir_dessin_dbx "c:/test/11.dwg") return (# nil) --> Work with ObjectDbx (Ouvrir_dessin_dbx "c:/test/11.dwg") return (# T) --> Work with AcadDocument Otherwise, hats, you learn quickly @+ Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 12, 2009 Share Posted June 12, 2009 Thanks for the pointer Patrick ~ much appreciated. I'll see about implementing that into my Attribute Extractor (in another thread). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.