×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

DELETE ALL IN THE BACKGROUND
2

DELETE ALL IN THE BACKGROUND

DELETE ALL IN THE BACKGROUND

(OP)
This code works well with one sheet

CODE --> vb

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.

RE: DELETE ALL IN THE BACKGROUND

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

RE: DELETE ALL IN THE BACKGROUND

(OP)
Well i got my morning coffee twicebigsmile. 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.

RE: DELETE ALL IN THE BACKGROUND

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.

RE: DELETE ALL IN THE BACKGROUND

+1 for Doug's follow up

thumbsup2

Eric N.
indocti discant et ament meminisse periti

RE: DELETE ALL IN THE BACKGROUND

(OP)
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 --> vb

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?

RE: DELETE ALL IN THE BACKGROUND

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

RE: DELETE ALL IN THE BACKGROUND

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 --> CATScript

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

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

RE: DELETE ALL IN THE BACKGROUND

(OP)
Thanks Ferdo. The code is working well. Seems like the Doug's code deleted the background.

RE: DELETE ALL IN 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

RE: DELETE ALL IN THE BACKGROUND

(OP)
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.

RE: DELETE ALL IN THE BACKGROUND

(OP)
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 --> VB6

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.

RE: DELETE ALL IN THE BACKGROUND

(OP)
Thanks. I tried to put On Error Resume Next in sub procedure instead of main. now it works.

Quote (Ferdo)

(use of sel, not all)
Not clearly understand that. Could you please explain.

RE: DELETE ALL IN THE BACKGROUND

(OP)
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.

RE: DELETE ALL IN THE BACKGROUND

(OP)
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?

RE: DELETE ALL IN THE BACKGROUND

I wouldn't use selection at all. What about just iterate through text elements on active sheet and delete them?

Tesak
http://scripts4all.eu/txtoncurve/ - Curved text for Catia V5

RE: DELETE ALL IN THE BACKGROUND

Try this:

CODE -->

Sub DeleteTexts()
    Dim doc
    Set doc = CATIA.ActiveDocument
    
    Dim sheet
    Set sheet = doc.Sheets.ActiveSheet
    
    Dim views
    Set views = sheet.views
    
    Dim view, textboxes, i

    For Each view In views
        Set textboxes = view.Texts
        
        For i = textboxes.Count To 1 Step -1
            textboxes.Remove i
        Next
    Next
End Sub 

Tesak
http://scripts4all.eu/txtoncurve/ - Curved text for Catia V5

RE: DELETE ALL IN THE BACKGROUND

(OP)
Thanks a lot. This is exactly what i need.

RE: DELETE ALL IN THE BACKGROUND

(OP)

Quote (Ferdo)


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

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

This is works pretty well but requires drawing sheet to be fitted on screen in order to to delete all entities. I tried to add command to fit drawing on screen and here is the issue comes. When fit all command is executed macro keeps to run and doesn't wait for Catia to finish fitting all drawing sheets on screen. Sleep command doesn't helps me. My goal is to delete everything from background except background view.

RE: DELETE ALL IN THE BACKGROUND

(OP)
Well this works not as i expected. I juts used twice For...Next. To fit all sheets in takes some time in Catia but code keeps to run to next loop that is deletion.

RE: DELETE ALL IN THE BACKGROUND

How about this?

CODE --> CATScript

Sub CATMain()

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

For j = 1 to DrwSheets.count
    Set DrwSheet = DrwSheets.Item(j)
    DrwSheet.Activate
    CATIA.StartCommand "Fit All In"
Next

''''''''''''''''''''''''''''''''''''''''''''''
MsgBox "STOP - Give me a break :-)"

For i = 1 to DrwSheets.count
    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
''''''''''''''''''''''''''''''''''''''''''''''
MsgBox "Let's fit all in again"

For z= 1 to DrwSheets.count
    Set DrwSheet = DrwSheets.Item(z)
    DrwSheet.Activate
    CATIA.StartCommand "Fit All In"
Next

End Sub 

Regards
Fernando

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

RE: DELETE ALL IN THE BACKGROUND

(OP)
i tried to use sleep instead of message. for the second example i get macro works much faster that catia and i don't actually get all drawing sheets fitted in. definitely that is because i remotely connected to my work PC. i'll give it a try tomorrow when i get to work.

Thanks Ferdo for your help.

Cheers.

RE: DELETE ALL IN THE BACKGROUND

if you google shellandwait you can have catia to start another process and wait for the return of the process before continuing... I m using this in some script where I unzip a file in a folder... had to make sure all unzipped before starting to do anything.

Eric N.
indocti discant et ament meminisse periti

RE: DELETE ALL IN THE BACKGROUND

(OP)
Thanks itsmyjob for shellandwait. I'll google for that. Don't want to start a new thread so I'm asking this question here.
I want to put a logo on my title block but i don't want to load a picture from local or network drive. Is there a way to store a picture inside VB6 project and then grab and insert it into Catia drawing?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources