Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

DELETE ALL IN THE BACKGROUND 2

Status
Not open for further replies.

JeniaL

Mechanical
Jun 3, 2014
547
IL
This code works well with one sheet
Code:
For Each DrwSheet In MyDrawingDoc.Sheets
Selection.Search "Drafting.View.Name='Background View' "
Selection.Search "Type=*,scr"
Selection.Remove (1)
Selection.Delete
drwviews.Item("Main View").Activate
Next
But i want to run thru all the sheets and delete everything in the background view.
In spite of For Each DrwSheet ....next, it's not going to next sheet.

Any help will be appreciated.

Cheers.
 
Replies continue below

Recommended for you

hmmm... it might

just it seems you don't use anything link to DrwSheet in your loop

maybe a DrwSheet.activate would help....

didn't you get your morning coffee yet or is it me?

[bigsmile]

Eric N.
indocti discant et ament meminisse periti
 
Well i got my morning coffee twice[bigsmile]. Where to insert DrwSheet.activate?
Tried to switch to background view and delete all using the same code to run thru all the sheets and it works but this command removed all the texts in my drawing.
 
Maybe try something along the lines of...

Dim oDrwView as DrawingView
Set oDrwView = DrwSheet.Views.Item(2)
call oDrwView.Activate

Selection.Add(oDrwView)
Selection.Search "Type=*,sel"
Selection.Remove (1)
Selection.Delete

DrwSheet.Views.Item(1).Activate

Mild Correction above.

 
+1 for Doug's follow up

[thumbsup2]

Eric N.
indocti discant et ament meminisse periti
 
Dougsnell thanks. Line Selection.Add(oDrwView) doesn't work for me. Just commented this line and code works perfect.
In my first post i forgot to take out selection to a separate Sub. Now code runs thru all the sheets.

But something definitely going wrong.
I run this code
Code:
selection.Search "Drafting.View.Name='Background View' "
'selection.Add (oDrwView)
selection.Search "Type=*,sel"
selection.Remove (1)
On Error Resume Next
selection.Delete
DrwSheet.Views.Item(1).Activate
Now if i try to type a text in the background and i can see no text.
In working views everything is ok. In addition to that i can't access background view on second or whatever sheet.
Jeez what that code done?
 
ok...

Let me try

For Each DrwSheet In MyDrawingDoc.Sheets
set bckgroundview = DrwSheet.Views.item(1) '<-- I m guessing here,but background view is always the same in each drawingsheet
Selection.Clear ' clearing selection just to be clean
Selection.add bckgroundview ' now we select the background view
Selection.Search "Type=*,sel" ' now we select everything in selection
Selection.Delete 'we delete the selection
Next

I m not in front of CATIA and this in not tested but the spirit is there, something like that should work

Eric N.
indocti discant et ament meminisse periti
 
Hi,

I remembered Doug's code behavior, it is really strange. That's why I done what you posted, JeniaL.
Hope what is below will work for you.

Code:
Sub CATMain()

Set DrwDocument = CATIA.ActiveDocument
Set DrwSheets = DrwDocument.Sheets

For i = 1 to DrwSheets.count

On Error Resume Next
Set DrwSheet = DrwSheets.Item(i)
DrwSheet.Activate

CATIA.StartCommand "Fit All In"

Set DrwView = DrwSheet.Views.Item("Background View")
DrwView.Activate

Dim mySelection As Selection
Set mySelection = DrwDocument.Selection
mySelection.Search "Drafting.View.Name='Background View' "

mySelection.Search "Type=*,scr"
mySelection.Delete

DrwSheet.Views.Item(1).Activate

Next
End Sub



Regards
Fernando

- Romania
- EU
 
Thanks Ferdo. The code is working well. Seems like the Doug's code deleted the background.
 
Hmmm, interesting. It looks like there have been some data model modifications that no longer allow for this generic method for clearing the background view any longer. At least in R24, there are DrwDressUp objects (one for each drawing view) that are being picked up in the search results. If you attempt to delete them by selecting through the Search results, you are prevented from deleting them. My guess is something in the search results is allowed to be deleted when it shouldn't be with that method.

Might be worthwhile to construct a query (Advanced Tab) in the CATIA Search tool that will capture all of the items you think may be included in the background views (Geometry, Text, Dimensions, etc) and use that as your search string for the VB method. If you run a CATIA search through the GUI, hit the 'Add to Favorites' icon, the text in the Query section can be used directly in the VB Search Method argument.

--Doug
 
Ferdo's code is useful. Doug thanks for the advanced search. Forgot about that.
With a code you wrote if with several sheets i can switch to background only with a first sheet. I can draw 2D geometry but now text.
For the rest of a sheets i can't access background. Seems like it's gone.

P.S I'll also try to submit this code to DS for their explanation.
 
Working on a macro and noticed if i do a search for an entity and then delete, macro will delete selected entity from all drawing sheets.
How to delete selection only from current sheet?

p.s How to tell VB not to show me error message?

i know exact reason why macro fails and i'm ok with that. I don't want to see a message about that.
Code:
CreateNewFileForMfg:
    On Error GoTo error_filter
    dTexts.GetItem("TitleBlock_Text_Title_6").Text = ProductDrawn.ReferenceProduct.UserRefProperties.Item("FILE FOR MANUFACTURING").ValueAsString
Item FILE FOR MANUFACTURING not existing on some sheets and that is the reason for Method GetItem failed.
 
Thanks. I tried to put On Error Resume Next in sub procedure instead of main. now it works.
Ferdo said:
(use of sel, not all)
Not clearly understand that. Could you please explain.
 
I'm using
selection1.Add drawingDocument1.Sheets.ActiveSheet.Views.ActiveView
selection1.Search "Drafting.Text,selection1"

Seems like ActiveSheet doesn't work. Delete command deletes a text from all drawing sheets.
 
selection1.Add drawingDocument1.Sheets.ActiveSheet.Views.ActiveView
selection1.Search "Drafting.Text,selection1"

This code is from another program where i just replace/delete text. I'm not running thru all drawing sheets and search for text however
Search command tells Catia to search thru the entire document. Google seems to be not really helpful.
What ActiveSheet really tells to Catia?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top