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!

insert the custom properties txt file?

Status
Not open for further replies.

Edcarlos

Industrial
Nov 17, 2012
6
BR
Vb script

hello
macro or vb script, import and insert the custom properties in part, starting from a txt file.???
 
Replies continue below

Recommended for you

Hi,

Ferdo

insert in catpart user custom properties, with a txt file.

exemplo

menu-editar-product-define othrer properties - external properties
load the txt file, myproperties.txt.

This file has properties defined for other catparts
I have a macro to insert the properties,
insert txt file loads the properties filled


is possible with one catscript or catvba??
I do not know how to start.

thank you
 
Hi,

Yes, is possible. You have to read in your macro line by line your txt file, set user parameters and values to them and write in User Defined Properties.

The only problem is your txt file to have always the same format, so you can read it correct in your macro. In that chm file you have an example how to write to a txt file, you can adapt to how to read from a txt, then put all together with your macro to insert properties.

If you still have problems, post your code here so we could help you.

Regards
Fernando

 
hello

Sub CATMain()
Set partDocument1 = CATIA.ActiveDocument
Set product1 = partDocument1.GetItem("")
Set parameters1 = product1.UserRefProperties
Set strParam1 = parameters1.CreateString("teste01", "")
strParam1.ValuateFromString "testando1"
Set product1 = product1.ReferenceProduct

End Sub

I use this to enter a new property, then ok
txt file to insert not know
I do not know vb program. about macro in Catia

I can help,

thank you
 
Hi,

Look at the code bellow, is a CATScript

Sub CATMain()

Dim partDocument1 As PartDocument
Dim part1 As Part
Dim parameters1 As Parameters

Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set parameters1 = part1.Parameters
Set product1 = partDocument1.GetItem(part1.Name)

Set parameters2 = product1.UserRefProperties
'~ ’Create Userproperties
Set strParam1 = parameters2.CreateString("MyUserProperty", "Hello Guys")

part1.update

End Sub

This was an example how user defined properties can be created (only one parameter). As far as I know, when importing a txt file, you will have same result like creating few user defined properties.
So, the idea is to read the text file line by line in macro, get from there the user properties and the values one by one from each line ( for example MyUserProperty2 and "Hello Guys 2" a.s.o.), then write them in strParam2 , strParam3.....

To read from a text file you can do it somehow like (pseudo code):

'~ ' ---------------------------------------
Const ForReading = 1, ForWriting = 2
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso_OpenTextFile("C:\temp\User_Parameter.txt", ForReading)
Do While MyFile.AtEndOfLine=false
ReadLineTextFile = MyFile.ReadLine

'''here you need write your code
Loop






Regards
Fernando

 
Hi,

Ferdo,

I'm learning, Vbscript
write the code, post here when ready

thank you,
 
hi

ferdo,

look at the code,

Sub CATMain ()

Set partDocument1 = CATIA.ActiveDocument
Set product1 = partDocument1.GetItem ("")

Set oCATIAFileSys = CATIA.FileSystem
Set oFile = oCATIAFileSys.GetFile (sDocPath & "C: \ Users \ Eddy and Sarah \ Documents \ Projects \ VBScript \ 123.txt")
Set oTextSteam oFile.OpenAsTextStream = ("ForReading")

Oline = oTextSteam.ReadLine
Set parameters1 = product1.UserRefProperties
Set strparam1 parameters1.CreateString = ("", "")
strparam1.Value = oline
strparam1.Rename "Edcarlos01"

Oline = oTextSteam.ReadLine
Set parameters2 = product1.UserRefProperties
Set strparam2 parameters2.CreateString = ("", "")
strparam2.Value = oline
strparam2.Rename "Edcarlos02"

end Sub

what do you think? can get better,
have to set the txt file. create and rename the parameters in macro
the property value import txt file

 
Hello,

I am ok to create userrefproperties, but how could you remove a userrefproperties that is already created in the doc ?? For example, i have a part with a userrefproperties called "TEST" and i want to remove it via a macro (in order to make a recursive loop on all a produxt)

Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top