I make a SAVEAS with opened file
Then I open the new file in ODBX mode because need to erase some layouts, but instead of delete the layouts of this new file opened in odbx mode, it point to the layouts with same name in current dwg and erase the layouts in this file instead in the odbx
I use
(setq fileName_doc (odbx-con)) ;open dwg in dbx mode
(vla-open fileName_doc fname)
(setq llayouts (vla-get-layouts fileName_doc)) ;get layouts of dbx opened
(setq lquedan (list "ZFER 01" "ZFER 02"))
(vlax-for lay llayouts
(setq laynam (vla-get-name lay)) ;nombre
(if (not (member laynam lquedan))
(vla-delete lay)
)
)
(vla-saveas fileName_doc fname)
(vlax-release-object fileName_doc)
Any idea on what I'm doing wrong or how can I solve the problem.
Handent of objects both files are the same because is a saveas,
Thanks
Solved! Go to Solution.
Solved by Sea-Haven. Go to Solution.
I tried this, you will need to download from www.lee-mac.com his OBDX lisp, you will need to redo how you pass the dont delete.
(defun c:test2 ( / _dellayout )
(if (not LM:ODBX)(load "ObjectDBXWrapperV1-2.lsp"))
(defun _dellayout ( doc )
(vla-delete (vla-item (vla-get-layouts Doc) "Layout2") )
(vla-Close doc :vlax-false)
)
(LM:ODBX '_dellayout (list "D:\\Alan\\test.dwg") T)
(princ)
)
(c:test2)
Thanks, sea.heaven but it still delete the LAYOUT from current opened DWG (in this case "DEMO.DWG") instead of deleting the layout in that opened in DBX mode ("ZFER 02.DWG")
I have attached both test dwg I have opened demo.dwg and need to delete in this case the "ZFER 02" layout in the "ZFER 02.DWG" opened in DBX mode.
I don't understand why it points to current opened doc instead to DBX mode opened doc
Thanks again
Hi,
You can not delete any layout with the use of ObjectDBX as far as I know, so you need to have the database of your drawing current to be able to delete a certain layout.
It is a bit weird it worked yesterday but not today, The doc variable is in lee's code which is the OBDX of the dwg to be changed I know I use doc so will look to see if its being duplicated some where. Get an error that layout does not exist.
Going to do a reboot now and test again.
Hi Gustavo,
Please try the code below which opens the drawing to be processed in the Documents collection of the current session of AutoCAD.
Once opened, the layout can be deleted, and then the drawing saved as a new name, and then closed.
I've opened the source drawing in read-only mode as a safe guard.
Substitute your file paths, drawing names and layout names where I've highlighted in red.
(setq col_Documents (vlax-get-property (vlax-get-acad-object) 'Documents) ; Open method: ; RetVal = object.Open(Name [, ReadOnly] [, Password]) ; Open source drawing in read-only mode obj_Document (vlax-invoke-method col_Documents' Open "C:\\Temp\\ZFER 02.DWG" :vlax-true)
; Get Layouts collection col_Layouts (vlax-get-property obj_Document 'Layouts) ; Use 'Item method with vl-catch-all-apply in case the layout does not exist obj_Layout (vl-catch-all-apply 'vlax-invoke-method (list col_Layouts 'Item "ZFER 02")) );setq (if (not (vl-catch-all-error-p obj_Layout)) ; Layout "ZFER 02" exists ; Delete layout (vlax-invoke-method obj_Layout 'Delete) );if (vlax-release-object col_Layouts) ; SaveAs method: ; object.SaveAs FileName [, FileType] [, SecurityParams] (vlax-invoke-method obj_Document 'SaveAs "C:\\Temp\\DEMO.DWG" acNative) ; Close method: ; object.Close [SaveChanges] [, FileName] (vlax-invoke-method obj_Document 'Close :vlax-true) (vlax-release-object obj_Document) (vlax-release-object col_Documents)
Regards,
Trevor
The question was to not open the dwg hence use OBDX.
The other alternative may be to use accoreconsole.exe which runs autocad like OBDX but using a script. Need to google some help.
I tried this from CMD line as a 1st step in a batch file maybe script.
"C:\Program Files\Autodesk\AutoCAD 2020\AcCoreConsole.exe" /i D:\alan\test.dwg /s D:\Alan\test.scr
The script needs loop about which to delete at "xxxx"
(setvar 'ctab "Model") filedia 0 -layout D "XXXX" close N
Whilst accoreconsole.exe does open the drawing it does not open any display rather just runs the commands, whilst opening dwgs in a session doing something then saving is reasonably fast just using a normal script, as another method open 2 copies of Autocad and run a script in one of the sessions, whilst you work in the other. There will be overhead though in terms of processing power.
I create different layouts inside a DGW, after that what I need is to create one DWG for each layout existing in this DWG, so I save the current DWG with each layout name and then I suppose I would be able to delete the layouts that doesn't belong to each dwg in ODBX mode
If a layout can NOT be deleted in ODBX mode as mentioned before, I will have to open and close each DWG and erase all layouts that does not belong, it is not a good solution because the display will show each DWG been opening and closing.
It is srabge that this method of erase a layout can not be done in ODBX mode
Ok your request is a bit different request than where I think some of us were going.
do save as for each layout name
write a script using layout names via lisp etc to open and close dwgs removing layouts starting with last dwg then close as you go.
The script could close the last dwg and using shell run a batch file using Accerconsole.
Ok @Sea-Haven Sorry to disturb you, go ahead 😊 👍
This appears to work tested on your dwg. It does not have any error checking for dwg exists so can be a problem.
A rule you can not have a layout in the dwg to be converted as the same name as a layout so I temp renamed ZFER 02 dwg to test.
The code is made in two parts the first reads the layout name and makes new dwgs, del layout1, it then writes a script to open each dwg and remove layouts, using Del layout2. Put the two lisps in a supported path so the 2nd can be found. Or set correct path to Del layout2.
It could all be rewritten to run under Accerconsole which should be a lot faster.
; Del layout1 ; make new dwgs as layout name and delete all layouts that are not dwg name ; by alanH consulting Sep 2019 ; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/delete-odbx-layout-delete-layout-of-current-opened-dwg/m-p/9000435#M389386 (defun dellayout1 ( / allays lst pref lname fo) (setvar 'ctab "Model") (setvar 'filedia 0) (setq alllays (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))) (setq lst '()) (setq pref (getvar 'dwgprefix)) (vlax-for lay alllays (setq lname(vla-get-name lay)) (if (/= lname "Model") (progn (setq lst (cons lname lst)) (command "saveas" "" (strcat pref lname)) ) ) ) ; now write script for rest of layouts removes for other dwgs (setq fo (open (strcat pref "layoutdel.scr") "w")) (write-line (strcat "(load " (chr 34) "Del layout2.lsp" (chr 34) ")" ) fo ) (write-line "close n" fo) (setq x (length lst)) (repeat (1- x) (write-line(strcat "open " (chr 34) pref (nth (setq x (1- x)) lst)(chr 34)) fo) (write-line (strcat "(load " (chr 34) "Del layout2.lsp" (chr 34) ")" ) fo ) (write-line "close n" fo) ) (close fo) ; load script (command "script" (strcat pref "layoutdel.scr"))
)
(dellayout1)
; delete all layouts that do not match dwg name ; by alanH ; error check wise should make sure layout exists (defun dellayout2 ( / dlname lay allays lname) (setq dlname(cadr (fnsplitl (getvar 'dwgname)))) (setq alllays (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))) (vlax-for lay alllays (setq lname(vla-get-name lay)) (if (or (= lname dlname) ; need remove dwg (= lname "Model") ) (princ "\nSkip") (vla-delete (vla-item alllays lname)) ) ) ) (dellayout2)
Thanks sea.heaven
This could be a solution even if is not the right I need because there other things to arrange that the app must do inside because each DWG will be different from the others, (delete some objects, modify others, etc) including the layouts. I told you the part that I was having problem
I will try to arrange things to lunch an script at the end, but seems it will not let me do to finish the job as desired
Anyway it's a pitty that a layout can not be modified in ODBX and other type of objects can
Thanks for your effort, time and dedication
Regards
Happy to help
Remove the line to run the script and at least you have a starting point of a file you can alter. I would open in excel then you can insert rows etc with other stuff to do. Copy and paste to notepad as the final script file.
Can't find what you're looking for? Ask the community or share your knowledge.