1

My question is : how to use the view identifier as parameter?

Code example:

Dim DrwDocument As DrawingDocument
Set DrwDocument = CATIA.ActiveDocument
Dim iParameter As Parameter
Set iParameter = DrwDocument.Parameters.Item("Drawing\Sheet.1\ViewMakeUp.1\Scale")
MyText.InsertVariable 0, 0, iParameter 

but how can i access to the view identifier, and use it as parameter?

thank you!

GisMofx
  • 982
  • 9
  • 27
user3503343
  • 25
  • 1
  • 4

1 Answers1

0

Ok, do do this you must first create a parameter in the DrawingDocument object.

So you would have something like this added to your current code:

Dim IndetifierParam as Parameter
Set IdentifierParam = MyDrawingDocument.Parameters.CreateString("ViewIdentifier", "A")
MyText.Text = "View ID:  "'note: there are two spaces from last character to end of the quote
MyText.InsertVariable Len(MyText.Text),0,IdentifierParam 'First parameter is insert position, second parameter is how many characters to overwrite, third is the parameter.

Now, in the drawing tree on the left you will see a Parameter Set with your new String Parameter. Double click the parameter and edit it...The drawing test will automatically update the drawing text with the changed parameter value. ALSO, as an added benefit, it's much easier in a VBA script to modify a parameter than the drawing text.

How to update or change this new Parameter:

IdentifierParam.ValuateFromString "A" 'add a string or variable here

Lastly, an extra tip, Go to Tools -> Options and click Parameters and Measure from the tree and on the First tab "Knowledge" check "With Value" and "With Formula" They are the first two checkboxes.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
GisMofx
  • 982
  • 9
  • 27
  • you can see this image to know what i mean by identifier : http://hpics.li/56ac594 thank you – user3503343 Apr 26 '14 at 19:28
  • @user3503343 Is that a section view? Like your other post: http://stackoverflow.com/questions/22893011/macro-catia-change-cut-view-text/22940623#22940623 – GisMofx Apr 26 '14 at 20:48
  • Yes... Imagine this scenario: i change the callout text "A" with a macro. after that if i want to change the name of the view "A-A", the callout isn't linked to this name ... so it doesn't change ... The idea is to rewrite the callout text using : MyText.InsertVariable 0, 0, iParameter but i should use the parameter which contains the view's identifier ... How can i do that? thank you – user3503343 Apr 26 '14 at 21:22
  • @user3503343 understood. There are a few way to do this...Let me give you an example and I will update my answer with the basic way to accomplish that. – GisMofx Apr 26 '14 at 21:28
  • @user3503343 I've updated my answer with the solution to your question. Let me know if you get it to work or have any other questions. – GisMofx Apr 26 '14 at 22:19
  • thank you, but i want to use the parameter which is the identifier of an existing view ... with your solution if i change the name of the view A-A, the callout will not change ... – user3503343 Apr 26 '14 at 22:34
  • @user3503343 With the solution above, you would need to create a parameter for view name and section call out..The way you change the names are you change the parameters' values. Very straight forward. Let me dig a little deeper and get back to you about the internal parameter you're referring to. It may be that the Identifier Parameter is not available via standard automation as in the previous question with the identifier text item. – GisMofx Apr 26 '14 at 22:40
  • i want to use this existing parameter : Sheet.1\A-A\ViewName.1\ident but it doesn't work ... – user3503343 Apr 26 '14 at 22:55
  • if i can add some caracters to the callout text without affecting its parameter, it will resolve my problem ... thank you. – user3503343 Apr 26 '14 at 23:22
  • i can't resolve this problem, i'm still waiting for your help. thank you – user3503343 Apr 27 '14 at 14:12
  • @user3503343 you can add plain text and then call insertvariable. You just need to tweak the parameters. Let me get you an example when I'm back in front of my computer. You want something like "my text [parametertext]"? – GisMofx Apr 27 '14 at 14:54
  • yes it's exactly what i want to do ... with the view identifier as [parametertext] – user3503343 Apr 27 '14 at 15:13
  • @user3503343 I've updated my answer to show an exmaple of how to add text then append a parameter to the end of the text...But you can add the parameter any where in the string – GisMofx Apr 27 '14 at 16:06
  • it still not working, because you created this new parameter,it's not the original one ... so if i change the identifier of the view "A-A", my text callout will not change ... i should use an existing parameter ... i searched, i found this parameter : Sheet.1\A-A\ViewName.1\ident , but i think that's a internal parameter which i cant use ... – user3503343 Apr 27 '14 at 16:14
  • @user3503343 I understand, but you need to drive the name of the view and section call out through the NEW parameters that are created..not the internal ones. In a script, you can change the value of the parameters and the texts will update automatically. Is there a reason that this solution won't work for you? Also, another way, but it's a little trickier, you can modifiy the relation for section view name, but it's less stable because the parameter name will change. You want to look at `OptionalRelation`. I still haven't found a way to directly access the ID parameter. – GisMofx Apr 27 '14 at 17:07
  • the problem is that i should also link the view name identifier with the new parameter ... ActiveView.GetViewName MyPrefix, MyIdent, MySuffix MyIdent should be equal to the new parameter ... – user3503343 Apr 27 '14 at 20:02
  • @user3503343 Exactly! Just create a new DrawingText object within the section view. Name it "ViewName" or whatever you want then set its Text value "My View Name " and then Create the link with the parameter(`insertvariable`) like you do with section view callouts. IMHO, it's the most direct way to do it. Drafting workbench is very cryptic when it comes to automation. There are many work around like this one here. – GisMofx Apr 27 '14 at 20:08
  • to which parameter i will link it? i cant acces to : Sheet.1\A-A\ViewName.1\ident ... – user3503343 Apr 28 '14 at 18:04
  • @user3503343 Correct. You can't link it. Create a NEW text object in the section view and link it to the NEW parameter (`IdentifierParam`) with `InsertVariable` – GisMofx Apr 28 '14 at 18:52
  • with this solution if i change the NEW text object ... the callout text will change it's ok... but the identifier of the section view will not change ... that's the problem... – user3503343 Apr 28 '14 at 20:59
  • @user3503343 With my previous answer on how to modify the idetifiers via selection command, you should be able to `insertvariable` on them. – GisMofx Apr 28 '14 at 21:56
  • thank you GisMofx, do you know how to add some caracters to the callout text without changing the parameter (equal to "A" in this case)? i think we can do that with : String = "String to insert after" MyTextRange.InsertAfter(String) but i dont know how? help – user3503343 Apr 29 '14 at 21:40
  • @user3503343 Can you post a screenshot? To answer your question, YES this is very easy. You should change the text of the callout and then InsertVariable after. Provide me with how you want your Section Callout Bubble to Look. – GisMofx Apr 29 '14 at 23:03
  • i want that the callout will be "A12", but if i change the name of the view to "B" it will automaticlly change to "B12", so i should conserve the parameter ... – user3503343 Apr 30 '14 at 06:41
  • You could just make the parameter the entire string you want to use. "A12" then change your parameter to "B12" OR you just `MySectionText.Text = "12"` and then `MySectionText.InsertVariable MyParameter, 0, 0` You would then make the same calls on the `MyDrawingViewName.Text = "Section View "` and then `MyDrawingView.InsertVariable Len(MyDrawingViewName.Text),0,MyParameter`[like I posted above in the answer] ...At this point I've more than sufficiently answered your question. Play around with those commands until you get the result you need. Would you please mark this the accepted answer? – GisMofx Apr 30 '14 at 14:48
  • Thank you GisMofx, you helped me lot. i think that i will be able to resolve the problem with this tips. – user3503343 Apr 30 '14 at 17:08