Problems with SubOccurrences

 

Hi,

i want to read a structure from an Assembly but the Suboccurrences are not visible.

I try so:

objApp = GetObject(, "SolidEdge.Application")

objAsm = objApp.ActiveDocument

objOccus = objAsm.Occurrences

 

For i = 1 To objOccus.Count 

   objOccu = objOccus.Item(i)

  If objOccu.Subassembly Then

     subOccus = objOccu.SubOccurrences

    If subOccus IsNot Nothing Then 

           objsubOccu = subOccus.Item(1)

          subOccus2 = objsubOccu.SubOccurrences

          If subOccus2 Is Nothing Then 

               objsubOccu.ThisAsOccurrence.MakeWritable() 'or another Acion in Solid Edge for read the Substructure

              subOccus2 = objsubOccu.SubOccurrences

         End If 

    End If

  End If

next i

but subOccus2 is still NOTHING. Why?

Kind regards,

JR

 

Posted by: JR
Post date: 5/26/2009 11:24:04 PM

11 REPLIES

RE: Problems with SubOccurrences

JR,

Maybe a silly question, but...

Are you checking if objsubOccu is a subassembly?. It can be a part, and so, there are no more suboccurrences and subOccus2 is nothing.

 

Posted by: Julian Guillo
Post date: 5/27/2009 6:48:45 AM

RE: Problems with SubOccurrences

 

Sure, objsubOccu is a subassembly with suboccurrences.

Note. If i made the Suboccurrences visible, and then will be made not visible again (the Struktur in EdgeBar is still visible), then the SubOccus2 is not nothing.

The problem is only, when the structure of objsubOccu is not loaded. If the object objsubOccu is made before the structure is loaded, then the properties of objsubOccu are not updated after load the structure. 

 

Posted by: JR
Post date: 5/27/2009 7:21:50 PM

RE: Problems with SubOccurrences

JR,

Have you tried to access the documents through Occurrences object?

When i have to go through an assembly i normally call a recursive fuction to write-read parts at any leve using the Occurrence objectl. It can be slower but it is safe.

It activates the parts if needed autonatically when you access an asm this way.

 

An example would be:

(it may have errors. I'm doing this by heart)

 

Sub goThroughASM(oASM as SolidedgeAssembly.AssemblyDocument, level as integer)

dim ocu as SolidedgeAssembly.Occurrence

for each ocu in oASM.Occurrences

ocu.MakeWritable 'Only if you need to write in the part document.

if ocu.subassembly then

processPart(ocu.OccurrenceDocument)

goThroughASM(ocu.OccurrenceDocument, level + 1) 'level is only useful to keep track of level inside the main asm.

else

processPart(ocu.OccurrenceDocument)

endif

next

 

sub processPart(oSEFile as Object)

if oSEFile.type=igAssemblyDocument then

...do your stuff for asm

elseif oSEFILE.type = ...

...do your stuff for par, etc...

endif

 

Posted by: Julian Guillo
Post date: 5/28/2009 6:37:13 AM

RE: Problems with SubOccurrences

Hi Julian,

 

this is off-topic, but I just wanted to say that it is good to have someone with your experience join the site (you answered the very first Solid Edge programming question I ever had!). I also wanted to thank you for all the help you've given in the short time since you joined up.

 

Keep up the good work.

 

Cheers

Calum

 

Posted by: Calum McLellan
Post date: 5/28/2009 12:25:11 PM

RE: Problems with SubOccurrences

Hi Julian,

 

the problem is, i need the suboccurrences and not the occurrences. I want to select the object in the topassembly and selection with occurrence is not at the same place like with suboccurrence (when the parent of the occurrence have different referenceplane than the topassembly).

 

 

 

 

Posted by: JR
Post date: 5/28/2009 7:29:32 PM

RE: Problems with SubOccurrences

To Calum,

Thanks for your words! Like anyone else, I will also need help for sure.

I'm very new using VB.net and still have problems dealing with COM, closing objects and cleaning memory.

I will post my questions when i study a little more how this stuff works.

I don't know about C++ or C# but can help with VB and SE.

Regards,

Julian

 

 

Posted by: Julian Guillo
Post date: 5/28/2009 9:40:28 PM

RE: Problems with SubOccurrences

JR,

I think it is a problem specific of your ASM file.

I tried something like your program with an ASM of mine, activating and deactivating all parts, making them visible and not visible, and it always worked well for me.

This is my code (practically the same as yours)

 

Dim objApp As SolidEdgeFramework.Application

Dim objAsm As SolidEdgeAssembly.AssemblyDocument

Dim objOccu As SolidEdgeAssembly.Occurrence

Dim objOccus As SolidEdgeAssembly.Occurrences

Dim subOccus As SolidEdgeAssembly.SubOccurrences

Dim objSubOccu As SolidEdgeAssembly.SubOccurrence

Dim subOccus2 As SolidEdgeAssembly.SubOccurrences

Dim i As Integer, j As Integer, k As Integer

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

objApp = GetObject(, "SolidEdge.Application")

objAsm = objApp.ActiveDocument

objOccus = objAsm.Occurrences

Debug.Print(objAsm.FullName)

For i = 1 To objOccus.Count

objOccu = objOccus.Item(i)

Debug.Print(" " & objOccu.OccurrenceFileName)

If objOccu.Subassembly Then

subOccus = objOccu.SubOccurrences

For j = 1 To subOccus.Count

objSubOccu = subOccus.Item(j)

Debug.Print(" " & objSubOccu.SubOccurrenceFileName)

If objSubOccu.Subassembly Then

subOccus2 = objSubOccu.SubOccurrences

For k = 1 To subOccus2.Count

Debug.Print(" " & subOccus2.Item(k).SubOccurrenceFileName)

Next

End If

Next

End If

Next i

End Sub

 

Posted by: Julian Guillo
Post date: 5/28/2009 10:21:59 PM

RE: Problems with SubOccurrences

 

Hi Julian,

if you make the structure vissible before, than is all Ok.

But try it without make this and make it visible in coding:

Open your assembly, make the objsubocu NOT visible. Save the assembly. Close then assembly. Open the assembly again.

Do nothing in Solid Edge. und change your coding:

  If objSubOccu.Subassembly Then

subOccus2 = objSubOccu.SubOccurrences

if suboccus2 is nothing then

objsubOccu.ThisAsOccurrence.Activate = True 

objsubOccu.Visible = True

'subOccus2 is still nothing:

 

subOccus2 = objsubOccu.SubOccurrences

End If

For k = 1 To subOccus2.Count

Debug.Print(" " & subOccus2.Item(k).SubOccurrenceFileName)

Next

End If

 

Posted by: JR
Post date: 5/28/2009 11:09:03 PM

RE: Problems with SubOccurrences

 

JR,

It seems to be a bug. I found a workaround to "wake up" the assembly.

Add these lines to the example, when you open the first subassembly. I'm doing an "In place activate (edit)", wait half a second and "close and return".

After this it seems it recognizes the suboccurrence objects.If objOccu.Subassembly Then 'Add from this objOccu.Select(True) 'Select the occurrence subassembly objApp.StartCommand(57872) 'In place activate System.Threading.Thread.Sleep(500) 'wait. it failed if not waiting in my tests. objApp.StartCommand(40013) 'close and return 'To this subOccus = objOccu.SubOccurrences 'Now subOccus is filled with data. For j = 1 To subOccus.Count ...Well, i don't know any other way. HTH,Julian

 

Posted by: Julian Guillo
Post date: 5/29/2009 6:46:52 AM