Publication Error with "/"

LECLERC Sebastien

Publication Error with "/"

Hi :)

I want do a MACRO VBA for make Publication on a Part....

It is oki for Publication a Point name "3-16 Point", with this code:

Public Sub pub_fasterners()

Dim sSel As Selection
Set sSel = CATIA.ActiveDocument.Selection

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

' Transforme la Part en Product
Dim product1 As Product
Set product1 = partDocument1.GetItem(1)

Dim publications1 As Publications
Set publications1 = product1.Publications

sSel.Search ("Name:'3-16 Point 01';all")
MsgBox sSel.Item(1).Value.Name

Dim reference1 As Reference
Set reference1 = product1.CreateReferenceFromName("Part1/!3-16 Points/'3-16 Point 01")
' Set reference1 = sSel.Item(1).Reference ' Déprécié depuis R14

Dim publication1 As Publication
Set publication1 = publications1.Add("3-16 Point 01")
publications1.SetDirect "3-16 Point 01", reference1

End Sub

 

But, if Point name is with a "/" as : "3/16 Point", the Reference no works, because he think / as lien command for separation... Soo, I don't know how I can do.... 

 

Thx.

Attachments

  • image_2021-10-24_045133.png (110.4k)

V!nc3nt N9, Engineer

RE: Publication Error with "/"
(in response to LECLERC Sebastien)

Hello Sebastien,

 

Maybe you can temporarily replace the character, get the element published and rename it back.

May not be a elegant way, but I think it may help:

 

Sub CATMain()

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

' Transforme la Part en Product
Dim product1 As Product
Set product1 = partDocument1.GetItem(1)

Dim publications1 As Publications
Set publications1 = product1.Publications

Dim sSel As Selection
Set sSel = CATIA.ActiveDocument.Selection

sSel.Search "Name='3/16 Point 02',all"
MsgBox sSel.Item(1).Value.Name

' Temporarily replace the slash character to a vertical bar
sSel.Item(1).Value.Name = Replace(sSel.Item(1).Value.Name, "/", "|")

Dim reference1 As Reference
Set reference1 = product1.CreateReferenceFromName("Part1/!3-16 Points/'3|16 Point 02")

Dim publication1 As Publication
Set publication1 = publications1.Add("3/16 Point 02")
publications1.SetDirect "3/16 Point 02", reference1

' Replace the vertical bar back to slash and publication should recognize the change
sSel.Search "Name='3|16 Point 02',all"
sSel.Item(1).Value.Name = Replace(sSel.Item(1).Value.Name, "|", "/")

 


End Sub

Edited By:
V!nc3nt N9, Engineer[Subscriber Members] @ Oct 25, 2021 - 09:47 AM (Asia/Singapore)

LECLERC Sebastien

RE: Publication Error with "/"
(in response to V!nc3nt N9, Engineer)

Thx you Vincent! xD

 

It is works, but.... Publication now has Bad Name...

 

I can't rename PUBLICATION wit VBA seem:

https://www.ibm.com/support/pages/apar/HD94249

V!nc3nt N9, Engineer

RE: Publication Error with "/"
(in response to LECLERC Sebastien)

Sebastian, thanks for the link to the IBM KB.

Michael Laursen

RE: Publication Error with "/"
(in response to LECLERC Sebastien)

Not a 100% sure... but you Could try "3//16 Point"  This works in you want to write a string with a "/"