cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

IS IT POSSIBLE TO AUTOMATE THE SELECTION PROCESS

avijayan-2
12-Amethyst

IS IT POSSIBLE TO AUTOMATE THE SELECTION PROCESS

Hi Everyone,

Dim selections As IpfcSelections
Dim selectionOptions As IpfcSelectionOptions

       

           
            selectionOptions = (New CCpfcSelectionOptions).Create("dtl_symbol")
            selectionOptions.MaxNumSels = 1
            selections = session.Select(selectionOptions, Nothing)

         

 

Here what i am trying to do is after the selection of one SYMBOL. is it possible to loop the selection process so that all same type SYMBOLshould be selected from the current sheet.

i tried to pass the selected SYMBOL to  "IpfcDetailItems". But is it possible to loop this so that i can get hold of all symbols by selecting one symbol. I tried using For loop but it didn't worked well.

Please tell me a method to select similar kind of symbols from a drawing template.

With Regards
Aghil.M

1 ACCEPTED SOLUTION

Accepted Solutions
sjuraj
13-Aquamarine
(To:avijayan-2)

Try this (I use j-link methods, but there are similar in VB):

String symbolName = "B"; // this is text value to compare

DetailItems items = owner.ListDetailItems(pfcDetail.DETAIL_SYM_INSTANCE, null);

DetailSymbolInstItem item = items.get(i);

DetailSymbolInstInstructions instructs = item.GetInstructions(false);

DetailVariantTexts textVals = instructs.GetTextValues();

DetailVariantText textVal = textVals.get(0);

String text = textVal.GetValue(); // this is String value of symbol instance


then you can compatre value:


if (text.equals(symbolName))

    item.Remove();

I hope this will help you.

View solution in original post

17 REPLIES 17
sjuraj
13-Aquamarine
(To:avijayan-2)

If your goal is to select all symbols of same type you can easily use search tool and search for symbol by its name:

sym_selecting.PNG

If you need to do it programmically you can create macro in you application. Remebmer your macro will run only after your program returns control to Creo. You can however do it pure programmically:

User will pick instance -> get name of it -> select all model items of dtl_symbol type with name of selecten instance -> remember to put your selections into buffer if the user will need to handle with this selection

avijayan-2
12-Amethyst
(To:sjuraj)

Hi skvarka,

Thanks for the reply. As you can see in the image all these balloons are having same symbol name. But my requirement is from this i need to select instances of same name. for Eg: I want to select all symbols with name "B".

I tried the find option but there i didnt find any option to select a perticular instance.Is there any way to get hold to that.

Capture.PNG

The second method what you said that looks interesting. Using selection option i selected one instance and later what i tried is i tried to pass the selection to "IpfcDetailItems" then i created a FOR loop to get the list of Symbol instance.

But its not working well.

Can you please explain me after user selecting one instance how to create a loop so that all symbol with same name should be selected or is there any other method to get this done. I want to delete the symbols of same name by one click.

With Regards

Aghil.M

sjuraj
13-Aquamarine
(To:avijayan-2)

In J-link there is method: pfcDetail.DetailSymbolInstInstructions.GetTextValues

I think there is similar in VBScript. This method should return all text values. You have only one text val. so you can compare if selected symbol has specific value.

avijayan-2
12-Amethyst
(To:sjuraj)

Hi skvarka juraj

Yes in VB-API also i have that API. I tried with that too. Here is the code what i Tried

Public Sub DeleteSymbolInstance(ByRef session As IpfcSession,
                                  ByVal symbolname As String, ByVal instancename As String)

    

Dim model As IpfcModel


        Dim drawing As IpfcModel2D
        Dim symInstructions As IpfcDetailSymbolInstInstructions
        Dim symItem As IpfcDetailSymbolInstItem

        Try
            model = session.CurrentModel
            If model Is Nothing Then
                Throw New Exception("Model not present")
            End If
            If Not model.Type = EpfcModelType.EpfcMDL_DRAWING Then
                Throw New Exception("Model is not drawing")
            End If
            drawing = CType(model, IpfcDrawing)

          

            Dim symbol As IpfcDetailSymbolDefItem = drawing.RetrieveSymbolDefinition(symbolname, Nothing, Nothing, False)   "Here first i retrieved the symbol"
        

          symInstructions = symbol.ListDetailItems(EpfcDetailType.EpfcDETAIL_SYM_INSTANCE)   "
            symInstructions = symbol.GetInstructions()                                                                               
            symInstructions.TextValues = instancename                                                                              
          

            symItem = drawing.GetDetailItem(symInstructions)                                                                 
            symItem.Remove()

      

         Catch ex As Exception
            MsgBox(ex.Message.ToString + Chr(13) + ex.StackTrace.ToString)
        End Try

End Sub




The Text highlighted in Blue : Here i tried to get hold on the Symbol instances : But i am getting error like object reference is not set to the instance of an object. i tried diff possibilities with in this loop but i am not getting the hold to the symbol instances.


If you have tried anything like this before can you tell what mistake i have done in that code.

i am not able to get hold to the symbol instance using "IpfcDetailSymbolInstInstructions" that is where i am facing problem.Please correct me where i have done the mistake.

Since this code didn't worked for me. i was trying some alternate method using SELECTION & LOOP.

With Regards

Aghil.M

sjuraj
13-Aquamarine
(To:avijayan-2)

symInstructions = symbol.ListDetailItems(EpfcDetailType.EpfcDETAIL_SYM_INSTANCE) returns array of all detail items. You have to get only one instance with get() method and then get instructions. After you get single instance of symbol you can chceck if it has text specific value. Remember GetTextValues also returns array of all possible texts in symbol. After you chceck value and delete symbol you will have to do it for every symbol instance throught loop.

avijayan-2
12-Amethyst
(To:sjuraj)

Hi skvarka juraj

Thanks a lot for the reply. Let me try that will get back to you.

With Regards

Aghil.M

avijayan-2
12-Amethyst
(To:sjuraj)

Hi skvarka juraj

I tried the method as you suggested. But after listing the symbol instances I am facing issues to get hold to the particular symbol.

Below is my code.

 

Dim model As IpfcModel

        Dim drawing As IpfcModel2D
        Dim symInstructions As IpfcDetailSymbolInstInstructions
        Dim symItem As IpfcDetailSymbolInstItem

        Try

           model = session.CurrentModel
            If model Is Nothing Then
                Throw New Exception("Model not present")
            End If
            If Not model.Type = EpfcModelType.EpfcMDL_DRAWING Then
                Throw New Exception("Model is not drawing")
            End If
             
            drawing = CType(model, IpfcDrawing)
            Dim owner As IpfcDetailItemOwner = CType(drawing, IpfcDetailItemOwner)
            Dim items As IpfcDetailItems = owner.ListDetailItems(EpfcDetailType.EpfcDETAIL_SYM_INSTANCE, 1)
            Dim item As IpfcDetailItem
            Dim i As Integer
            Dim vartets As IpfcDetailVariantText

            For i = 0 To items.Count - 1

                item = items.Item(i)                        
               symInstructions = item.GetType()
                vartets = symInstructions.TextValues(instancename)
                symItem = drawing.GetDetailItem(symInstructions)
                symItem.Remove()  

            Next

 

The first method which I tried was actually giving me a null array now this method I am able to list the items. But After getting the item how to pass a symbol instruction to get hold to a particular symbol instance. I am not getting how to use the get method inside the loop. Can you please explain me how to do that.

I created one string variable and I tried to cast it to "item.GetName(Symbol Instance Name)" but  I got error saying Get name is not a function of "IpfcDetailItem" .Now for the above method I got error as below.

Please guide me to find out the mistake what I did in my coding.

With Regards

Aghil.M

sjuraj
13-Aquamarine
(To:avijayan-2)

Try this (I use j-link methods, but there are similar in VB):

String symbolName = "B"; // this is text value to compare

DetailItems items = owner.ListDetailItems(pfcDetail.DETAIL_SYM_INSTANCE, null);

DetailSymbolInstItem item = items.get(i);

DetailSymbolInstInstructions instructs = item.GetInstructions(false);

DetailVariantTexts textVals = instructs.GetTextValues();

DetailVariantText textVal = textVals.get(0);

String text = textVal.GetValue(); // this is String value of symbol instance


then you can compatre value:


if (text.equals(symbolName))

    item.Remove();

I hope this will help you.

avijayan-2
12-Amethyst
(To:sjuraj)

HI skvarka juraj

So sorry for the late reply. i was on vacation.

Thanks a lot for the help. it solved my issue. Now i am able to delete symbols as i need.

Once again thankyou for the support shown.

With Regards

Aghil.M

sjuraj
13-Aquamarine
(To:avijayan-2)

No, problem, glad I could help you. Feel free to contact me in the future

avijayan-2
12-Amethyst
(To:sjuraj)

Sure Bro.

I have a small query. I have completed now one project using VB-API. and i going to submit the "exe" file to the customer. so when i give the file should i ask my customer to add the environmental variables. run the VBAPI_REGISTER.bat file and all.

because i run this from one of my collegues PC and i got a error message as follow's.

sjuraj
13-Aquamarine
(To:avijayan-2)

I saw this question but I cant help you with this. I am not familiar to VB, only with J-link. I can help you with Creo API. sry

avijayan-2
12-Amethyst
(To:sjuraj)

Hi skvarka juraj

How are you?

A small update on the same. I tried this deleting symbol instance code in a very old creo drawing, which is having almost 100 symbols and 200 + instances used in that drawing. That time the code is not able to find out the instances, loop is running but in between its stopping. so what i tried is instead of looping through all the symbol instances if we specify a particular symbol it will be easy for code to find out the instance.

Here is what i tried.

            Dim symInstructions As IpfcDetailSymbolInstInstructions

            Dim symItem As IpfcDetailSymbolInstItem

            Dim symbol As IpfcDetailSymbolDefItem    

            Dim owner As IpfcDetailItemOwner = CType(drawing, IpfcDetailItemOwner)

            Dim items As IpfcDetailItems = owner.ListDetailItems(EpfcDetailType.EpfcDETAIL_SYM_INSTANCE, k)

            Dim items1 As IpfcDetailItems = owner.ListDetailItems(EpfcDetailType.EpfcDETAIL_SYM_DEFINITION, k)

           For m = 0 To items1.Count - 1

                symbol = items1.Item(m)

              

                    If symbol.ToString = symbolname Then

                              For i = 0 To items.Count - 1

                                  symItem = items.Item(i)

                                  symInstructions = symItem.GetInstructions(False)

                                  varTexts = symInstructions.TextValues()

                                  varText = varTexts.Item(0)

                                  ins = varText.Value()

                                  If ins.Contains(instancename) Then

                                  symItem.Remove()

                                  End If

                              Next

              

                     End If

            Next

The highligted in Blue color are the newly added lines. "symbolname" is a string which will represent the symbol, Here the first loop is running, but its not going to the inner loop.
I hope you understood what i am trying.

How can i restrict the loop so that it will check on a particular symbol instances.

With Regards

Aghil,M

sjuraj
13-Aquamarine
(To:avijayan-2)

If you need to delete only instances of specific symbol you can chceck if the instance is instance of specific symbol (you can compare symbol name defined as parameter) and then chceck its text value.  owner.ListDetailItems collects all instances of all symbols.

avijayan-2
12-Amethyst
(To:sjuraj)

Hi skvarka juraj

Thanks for the reply. as you mentioned i need to delete instance of a specific symbol. but it should be based on the symbol name what i give.

For eg: if i have 2 symbol in my creo drawing template. i will specify the name of the symbol first so in our for loop how to sort it, is where i am stuck now

"Dim symbol As IpfcDetailSymbolDefItem = owner.RetrieveSymbolDefinition(symbolname, Nothing, Nothing, False)"

I tried using the above method also. but after retrieving the symbol now how to compare it in the for loop so that only those instance which is part of the symbol should be passed through it.

Please give me some hint how best i can do this.

With Regards

Aghil.M

sjuraj
13-Aquamarine
(To:avijayan-2)

Previous comment should solve your problem

avijayan-2
12-Amethyst
(To:sjuraj)

Hi skvarka juraj

I tried like this.

          Dim owner As IpfcDetailItemOwner = CType(drawing, IpfcDetailItemOwner)

        

            symbol = owner.RetrieveSymbolDefinition(symbolname, Nothing, Nothing, False)

            Dim items As IpfcDetailItems = symbol.ListDetailItems(EpfcDetailType.EpfcDETAIL_SYM_INSTANCE)     " This returns nothing"

Can you brief how to compare the instance is of a specified symbol parameter.

Sorry for the trouble.

With Regards

Aghil.M

Top Tags