What's new

Loop through and Count/Display Configurations

RCH_Projects

Alibre Super User
from: viewtopic.php?f=28&t=10724&p=66742&hilit=configuration#p66742
WoodWorks said:
...
I am basically converting Alex Franke's sample program (Version, Loop through and Count/Display Configurations).
My main problem is the looping through the Configurations.

It is the basis of most of my Parameter and Configuration programs. I have them running in Visual Basic, but I
think IronPython might have some advantages, and wish to learn more. Thanks

I am coding in VBA for Excel (2007 at the moment).
I've been eyeing Alex Franke's codecreations for some time now to see if his samples come back up but I don't see it happening.

It is easy enough to change the "active configuration", to loop through the values but is very undesirable.
It updates the files and there are times when applying the wrong configuration can create incidental havoc on an assembly or part.
With polish I'll share the excel utility so I really don't want to use bad practices.

There is a chance of adapting the VBA code to Visual Studio basic to interact with the free spreadsheets so I want reliable code worked out first.

I've tried cloning byval with class and memento techniques but where I use the "xcopy" references the source parts/assembly update as well.
I preserve the AD structures to avoid a lot of code overhead which may prevent the clone barrier from standing.

While my current goal is a good inquiry utility it can be expanded to "updating" with Excel code. A good Clone/unmodified image of session or hook would make this simple.

Implementing the Object.MemberwiseClone Method might give a good solution if a DeepCopy() approach works.
The trouble is the translation or conversion from other languages.

I've put in a lot of time on what is probably already solved by others.
If you have something worked out, whatever language, post it up and maybe I can adopt it.

I've tried variations on techniques from the web but something is defeating me.
With other code to work on I need to cut it off without some insight, and it wont be a disaster to me to use my utility, so if there is a clear problem with the code approach below shout out.
Even a good "why" or "wherefore" would help.

start of standard module:
Code:
Type MyDesignSession
    xCopy As IADDesignSession
End Type

Class module "xPcoAD_L31Part_DesignSession":
Code:
Private Pass_L31Part_DesignSession As MyDesignSession

Public Property Get xCopy() As IADDesignSession
    Set xCopy = Pass_L31Part_DesignSession.xCopy
End Property

Public Property Let xCopy(ByVal IADDesignSessionCopy As IADDesignSession)
    Set Pass_L31Part_DesignSession.xCopy = IADDesignSessionCopy
End Property

Private Sub Class_Initialize()
End Sub

Private Sub Class_Terminate()
End Sub

Code implementation in standard module:
Code:
Dim xPUoAD_L31Part_DesignSession As xPcoAD_L31Part_DesignSession 
Set xPUoAD_L31Part_DesignSession = New xPcoAD_L31Part_DesignSession 
xPUoAD_L31Part_DesignSession.xCopy = PUoAD_L31Part_DesignSession ' (the part designsession should clone here)

... ...

Set xPUoAD_L31Part_DesignSession.xCopy.ActiveConfiguration = _
    xPUoAD_L31Part_DesignSession.xCopy.Configurations.Item(MYv_Configurations)
Properly implemented that last line should not update the actual, or "source", AD records/files.

Thanks for any info.

Roger
 

isaacb

New Member
If your intention is just to loop through and count/display configurations, that should be simple enough, unless I have misunderstood. You don't even have to touch the ActiveConfiguration property.

I am not fluent with VBA, so I will keep the example in C# so I don't make any errors. It should be easy enough to convert to VBA.

C# code:

Code:
List<IADConfiguration> configurations = new List<IADConfiguration> ();
 
foreach (IADConfiguration configuration in designSession.Configurations)
{
   configurations.Add (configuration);
}
 
// Do something meaningful with the list of configurations.
// ...
 
// Get the number of configurations
int count = configurations.Count;
 
// Print their names to the console
foreach (IADConfiguration configuration in configurations)
{
    Console.WriteLine (configuration.Name);
}

Of course, if your need for a true deep copy extends further than the need above, then I can't help much there.
 

RCH_Projects

Alibre Super User
OH! - were it only that easy.
I should have explained the (apparent) issue with more depth.

The IADSession contains "Parameters" aka the active configuration "Equation" values.
A subroutine establishes the Alibre Hook and stores a part session in "PUoAD_L2_Session" - which can be derived as public object Level 2 IADSession.

then basically drill down to a configuration:
Code:
Public My_Hook As IAutomationHook ' Holds Alibre Automation My_Hook object

Public PUoAD_L1_Root As IADRoot ' Holds Alibre Root object

Public PUoAD_L2_Session As IADSession ' Holds Alibre Session Object
Public PUoAD_L3Part As IADPartSession ' Holds Alibre Part Session object
Public PUoAD_L31Part_DesignSession As IADDesignSession

Public PUoAD_L4_Configurations As IADConfigurations
Public PUoAD_L4_Configuration As IADConfiguration

Public PUoAD_L41Part As IADPartSession ' Holds Alibre Part Session object

Public PUoAD_L41Part_DesignSession As IADDesignSession

Public PUoAD_L51Part_Features As IADPartFeatures
Public PUoAD_L51Part_Feature As IADPartFeature
Public PUoAD_L60Part_ExtrusionFeature As IADExtrusionFeature
Public PUoAD_L61Part_RevolutionFeature As IADRevolutionFeature


Code:
Set PUoAD_L3Part = PUoAD_L2_Session
Set PUoAD_L31Part_DesignSession = PUoAD_L3Part
Dim MyArrayx(10) As IADConfiguration
Dim MYv_TestLoopCount As Integer
MYv_TestLoopCount = 0
Set PUoAD_L4_Configurations = PUoAD_L31Part_DesignSession.Configurations

With Configurations
    For Each Item In PUoAD_L4_Configurations
        Set MyArrayx(MYv_TestLoopCount) = Item
        Set PUoAD_L4_Configuration = Item
        MYv_TestLoopCount = MYv_TestLoopCount + 1
    Next
End With

The problem is that in all the objects derived from "PUoAD_L2_Session"; the "Features" under all configurations reflect only the equation values in the "ActiveConfiguration".

"PUoAD_L2_Session"

Array configuration 1

Array configuration 2


For example the value for "configDepth" is the same for both array entries, but are different values.
The difference is not reflected until the other configuration(s) are set to the ActiveConfiguration.
It also affects suppression status et al, so that comes along as well.

Setting ActiveConfiguration brings up two solid issues.
1. The part/assembly is updated and, utility-wise not a good thing to impose on other potential users.
2. Blindly changing a configuration can place a part or assembly in a corrupted arrangement from which it cannot be recovered.

I myself have had complex assemblies that if changed with a large increment constraints flipped in an unintended arrangement requiring discarding the (usually unsaved) changes.
(Perhaps resolved since older releases)

My need/intent is a comprehensive query to examine and resolve naming, value and other discrepancies for larger projects, and work up some solid and safe foundation code for future utilities.
It involves examination of features, sketches and any other applicable aspects.
This is a nagging little problem that cans the whole thing to others. I've been at it for at least a week and tried a lot, learned a lot, but changing the ActiveConfiguration (on the live part) is very sloppy/desperate.
 

Attachments

  • Config AD Session.jpg
    Config AD Session.jpg
    213.3 KB · Views: 15
  • Config Array 0.jpg
    Config Array 0.jpg
    201 KB · Views: 9
  • Config Array 1.jpg
    Config Array 1.jpg
    195.9 KB · Views: 13

isaacb

New Member
I see.

The only solution I can think of is to save temporary files for each configuration, using AlibreSession.SaveAs(...). Then, you can perform your operations on those "temporary" files, and clean them up(delete them) when you are finished. In this way you can keep the original file in its pristine state, since the only operations were performed on temporary files.

Unfortunately, this is a somewhat expensive operation to perform. If performance is an issue, then this approach might not be satisfactory.
 

RCH_Projects

Alibre Super User
A real trick box huh.

Save as on a sub-assembly or part and the top assembly is linked to them instead. A file pending save no longer exists as its origional name.
Creating a new hook and opening the named file doesn't get changes since last save.

Early on I looked at MemberwiseClone which has some promise but the difference between shallowcopy and deepcopy seems to blur with AD classes.
If the code at http://msdn.microsoft.com/en-us/library/e5kfa45b functions as claimed the problem is solved.
It may have failed the first time I tried but will try it fresh.
I suspect changes to the "copy" will still update the source.

"Fishing" around like this burns a lot of time. I just wonder / want to know if I'm looking for a "fountain of youth".


Code:
    ' Return a copy of this point object by making a simple field copy. 
    Public Function Copy() As Point 
        Return CType(Me.MemberwiseClone(), Point)
    End Function 
End Class   

NotInheritable Public Class App
    Shared Sub Main() 
        ' Construct a Point object. 
        Dim p1 As New Point(1, 2)

        ' Make another Point object that is a copy of the first. 
        Dim p2 As Point = p1.Copy()

        ' Make another variable that references the first Point object. 
        Dim p3 As Point = p1

        ' The line below displays false because p1 and p2 refer to two different objects.
        Console.WriteLine([Object].ReferenceEquals(p1, p2))

        ' The line below displays true because p1 and p2 refer to two different objects  
        ' that have the same value.
        Console.WriteLine([Object].Equals(p1, p2))

        ' The line below displays true because p1 and p3 refer to one object.
        Console.WriteLine([Object].ReferenceEquals(p1, p3))

        ' The line below displays: p1's value is: (1, 2)
        Console.WriteLine("p1's value is: {0}", p1.ToString())

    End Sub 
End Class 
' This example produces the following output: 
' 
' False 
' True 
' True 
' p1's value is: (1, 2)
 

isaacb

New Member
RCH_Projects said:
Early on I looked at MemberwiseClone which has some promise but the difference between shallowcopy and deepcopy seems to blur with AD classes.

You are correct in that there is some blur here, the cause of it due to the copy of the underlying reference types. From the MSDN link that you posted:

If a field is a reference type, the reference is copied but the referred object is not; therefore, the original object and its clone refer to the same object.

When dealing with Alibre through API, there are some private reference fields that are not exposed to the user. In essence, when you perform a MemberwiseClone, you are still getting the same underlying reference types, so those actions will still affect the underlying session.

RCH_Projects said:
I just wonder / want to know if I'm looking for a "fountain of youth".

It appears so.
 

RCH_Projects

Alibre Super User
If a field is a reference type, the reference is copied but the referred object is not; therefore, the original object and its clone refer to the same object.
Mmm, yes, at http://msdn.microsoft.com/en-us/library ... clone.aspx

Some time I'll try serialization. Maybe see what happens if I open a second hook and plow it into that :twisted: .
So much depends on the class implementation.

Meantime, if someone logs in with a ready answer ...
 
Top