TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: cadman6735 on March 09, 2011, 10:32:00 AM
-
Hi all,
I usually post over at CadTutor but the site is down for repair. I try not to jump back and forth between forums because I am not sure how you guru's look upon this.
This being said, I could really use some assistance.
All I want to do is check my acad file to see if a PlotTab is there and if it is, delete it and move on. I have come close but the more I try to figure it out the more screwed up I become and the more confused I become. This should be simple but I am mind-boggeled.
(defun C:test ( / deleteLayout)
(vl-load-com)
(setq
acadObject (vlax-get-acad-object)
acadActiveDocument (vla-get-ActiveDocument acadObject)
acadLayouts (vla-get-Layouts acadActiveDocument)
)
;-----------------------------------------------------------------------------------------
(vla-StartUndoMark acadActiveDocument) ;Start of UNDO
;-----------------------------------------------------------------------------------------
(vlax-for eachLayout acadLayouts
(if
(eq (vla-get-name eachLayout) Plot)
(progn
(setq Layout eachLayout)
(vla-delete Layout)
)
)
)
;-----------------------------------------------------------------------------------------
(vla-EndUndoMark acadActiveDocument) ;End of UNDO
;-----------------------------------------------------------------------------------------
(princ)
)
Thanks
-
The 'Plot' symbol doesn't seem to have a value.
Otherwise I would assume you wanted to compare strings:
(eq (vla-get-name <layout>) "Plot")
You might want to also use strcase to avoid case-sensitivity.
-
My two cents, quickly looking over your code:
(defun C:test ( / deleteLayout)
(vl-load-com)
(setq
acadObject (vlax-get-acad-object)
acadActiveDocument (vla-get-ActiveDocument acadObject)
acadLayouts (vla-get-Layouts acadActiveDocument)
)
;-----------------------------------------------------------------------------------------
(vla-StartUndoMark acadActiveDocument) ;Start of UNDO
;-----------------------------------------------------------------------------------------
(vlax-for eachLayout acadLayouts
(if
(eq [color=red](strcase[/color] (vla-get-name eachLayout)[color=red])[/color] [color=red]"PLOT"[/color])
(progn
(setq Layout eachLayout)
(vla-delete Layout)
)
)
)
;-----------------------------------------------------------------------------------------
(vla-EndUndoMark acadActiveDocument) ;End of UNDO
;-----------------------------------------------------------------------------------------
(princ)
)
Thanks
-
The 'Plot' symbol doesn't seem to have a value.
Otherwise I would assume you wanted to compare strings:
(eq (vla-get-name <layout>) "Plot")
You might want to also use strcase to avoid case-sensitivity.
You beat me to it. :kewl:
-
You beat me to it. :kewl:
And with your carefully code modifications, he now has a complete answer - good job 8-)
-
Hey guys :-)
If it isn't the 2 out of the 3 musketeers that always come to my rescue. (One of these days I will have enough knowledge to repay the education you guys give me to someone else)
Anyway
strcase was the missing piece of my puzzle and this routine works like a charm. I can move on... Thanks
-
FYI.... from the help, for the Delete method.
Remarks
When you delete an object in a collection, all remaining items in the collection are reassigned a new index based on the current count. You should therefore avoid loops that delete an object while iterating through the collection.
-
Good point Tim, I suppose the best way would be to create a list and mapcar 'vla-delete the list.
-
Tim
I read this too in the help while I was trying to figure out how to delete layout tabs with out using (command "-layout")
But since I am only looking for a layout with the Name "Plot" this didn't seem relevent to my situation...
Should I be rethinking my approach?
-
I would do it correctly, just so you get in the habit. Who knows what else might happen later on.
Good point Tim, I suppose the best way would be to create a list and mapcar 'vla-delete the list.
I would use a ' foreach ' and not a mapcar, just because who cares what is returned. I'm trying to get into that habit. If I want a list returned, then I use mapcar, but if not, then I use foreach.
-
Lee
I was wondering what you ment by this:
The 'Plot' symbol doesn't seem to have a value.
Took me a while to figure it out but yes, I ment qoute my Plot "Plot"
As I said I re-wrote this so many time in so many different directions, each getting close to what I wanted but none of them being exact so I forgot to quote my "plot" This too was a causeing an issue that I did not see.
Thanks
-
I would use a ' foreach ' and not a mapcar, just because who cares what is returned. I'm trying to get into that habit. If I want a list returned, then I use mapcar, but if not, then I use foreach.
I do find myself using mapcar excessively - sometimes just because it looks more succinct:
(foreach layout <layoutlist>
(vla-delete layout)
)
(mapcar 'vla-delete <layoutlist>)
-
I would do it correctly, just so you get in the habit.
This is what I want to do, the only problem is I don't know the proper way till someone points it out to me. :oops:
Who knows what else might happen later on.
This is what I am trying to avoid, the unknown issues for later, only experiance can provide me this, which I have little of.
I will take your advise and see where it leads me but I am afraid I may not understand till it bites me in the a$$.
Thanks for leading me in a good direction.