×
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

CATScript - Need Help with Adding to my documents list

CATScript - Need Help with Adding to my documents list

CATScript - Need Help with Adding to my documents list

(OP)
I have a small routine that I am trying to use to get a text list of unsaved documents in my CATIA V5 session. I think I'm doing something that CATScript doesn't like, but should be okay in Visual Basic. When I run the script it doesn't like my method of adding to the PartList.

CODE

Sub CATMain()

Dim 	AllParts 	
Dim 	OpenPart 		
Dim 	QueryPart as string 			
Dim 	PartList as string
Dim 	J as integer

Set AllParts = CATIA.Documents

J = 0
For Each OpenPart In AllParts
	QueryPart = OpenPart.Name
	If OpenPart.Saved = False Then
		PartList.Add(QueryPart)
		J=J+1
	End If
Next

MsgBox "There are " & J & " unsaved documents"
MsgBox PartList

End Sub 

Please point out my (hopefully) simple error.

Thanks,
Jeff

RE: CATScript - Need Help with Adding to my documents list

Does it work if you change the variable declaration to:

Dim PartList as object

RE: CATScript - Need Help with Adding to my documents list

(OP)
No, it throws the same error:

"Object required: 'PartList'"

Jeff

RE: CATScript - Need Help with Adding to my documents list

(OP)
I also tried just

Dim Partlist

(without declaring a type) but that didn't work either. It gave me the same error. So now I'm wondering if it is related to my use of .Add as opposed to the specific type of variable.

Jeff

RE: CATScript - Need Help with Adding to my documents list

Hi,

I don't know and I didn't see something like what are you trying to do in CATIA automation documentation but I would try something else.

If you are working with files on hard disk you can check for each file in folder in vbscript which file was saved in last 30 minutes for example

CODE --> vbscrpt

With CreateObject("Scripting.FileSystemObject")
    For Each File In .GetFolder("c:\Temp\").Files
        If DateDiff("n", File.DateLastModified, Now) < 30 Then
            ' File has been modified in past 30 minutes.
            Msgbox "Got one" & "    " & File.Name
        End If
    Next
End With 

Starting with this, you can imagine various scenarios like getting the path and the name for each part or product loaded in CATIA, input the starting time of the session and exclude or include in your DateLastModified calculation criteria what you want.

Regards
Fernando

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

RE: CATScript - Need Help with Adding to my documents list

(OP)
Thanks Ferdo, but I know this code can work, because if I simply report with a MsgBox, it does tell me if the file is unsaved (modified) or not.

CODE

For Each OpenPart In AllParts
	QueryPart = OpenPart.Name
	If OpenPart.Saved = False Then
		MsgBox QueryPart & "Is Unsaved"
		'PartList.Add(QueryPart)
		J=J+1
	End If
Next 

But as soon as I uncomment/activate the PartList.Add line it throws the error. That is why I think it is just a programming error on my part, but I don't know how to fix it.

Jeff

RE: CATScript - Need Help with Adding to my documents list

(OP)
Okay, as I suspected, I was missing something from VBScript:

CODE

Set PartList = CreateObject("System.Collections.ArrayList") 

Once I added this, the error went away. Now to figure out the rest of my code...maybe stay tuned for a new post...

Thanks,
Jeff

RE: CATScript - Need Help with Adding to my documents list

(OP)
Thanks for the star.

Jeff

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