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

IS IT POSSIBLE TO AUTOMATE THE SELECTION PROCESS

SOLVED
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

Re: IS IT POSSIBLE TO AUTOMATE THE SELECTION PROCESS

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

Re: IS IT POSSIBLE TO AUTOMATE THE SELECTION PROCESS

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

Re: IS IT POSSIBLE TO AUTOMATE THE SELECTION PROCESS

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

Re: IS IT POSSIBLE TO AUTOMATE THE SELECTION PROCESS

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.

Re: IS IT POSSIBLE TO AUTOMATE THE SELECTION PROCESS

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

Re: IS IT POSSIBLE TO AUTOMATE THE SELECTION PROCESS

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.

Re: IS IT POSSIBLE TO AUTOMATE THE SELECTION PROCESS

Hi skvarka juraj

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

With Regards

Aghil.M

Re: IS IT POSSIBLE TO AUTOMATE THE SELECTION PROCESS

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

Re: IS IT POSSIBLE TO AUTOMATE THE SELECTION PROCESS

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

Re: IS IT POSSIBLE TO AUTOMATE THE SELECTION PROCESS

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

Announcements
LiveWorx Call For Papers Happening Now!