cancel
Showing results for 
Search instead for 
Did you mean: 

UFSession.Assem.AskComponentData Error

Pioneer
Pioneer

Hi,

 

Im could not able to get AskComponentData (C Sharp)  this to work out

Im getting this method has some invalid arguments. Im not able to catch what exactly it is.

 

could anybody suggest.

 

 

C Reference Documentation mentions as below.

UF_ASSEM Functions UF_ASSEM_ask_component_data
 

Defined in: uf_assem.h

Overview
Returns data about an instance or a part occurrence. The instance_name
output is always the name of the instance, even when a part occurrence is
passed to the function. Note that the names of the part occurrence and its
corresponding instance can be different. The refset_name can be different
between a part occurrence and its instance. The full 9 elements of the
csys_matrix are returned. The full transformation matrix is also
returned. The transformation matrix is the 4x4 matrix that combines
the origin and CSYS-matrix into a single matrix.

The format of the 4x4 transform is that the elements:

transform[0][0], transform[0][1], transform[0][2]
transform[1][0], transform[1][1], transform[1][2]
transform[2][0], transform[2][1], transform[2][2]

form a 3x3 orthnormal rotation matrix, the elements :

transform[0][3]
transform[1][3]
transform[2][3]

represent a (X, Y, Z) translation in the units of the part containing the
component, element

transform[3][3]

is always set to 1.0, and the remaining elements are always set to 0.0.

CAUTION: If the reference set of the component you are asking for
data on is set to "Entire Part", the string returned by
UF_ASSEM_ask_component_data for refset_name (third argument)
is "None".
UF_ASSEM Functions
tag_tcomponentInputTag of instance or part occurrence
charpart_name [ MAX_FSPEC_BUFSIZE ]OutputName of part
charrefset_name [ UF_OBJ_NAME_BUFSIZE ]OutputName of the reference set in use
charinstance_name [ UF_CFI_MAX_FILE_NAME_BUFSIZE ]Outputname of instance
doubleorigin [ 3 ]OutputPosition of component
doublecsys_matrix [ 9 ]OutputCoordinate System Matrix
doubletransform [ 4 ] [ 4 ]OutputTransformation Matrix

 

And my code is 

string sPartName = null;
string sRefSetName = null;
string sInstanceNameOfPart = null;
double[] origin = new double[2] ;
double[] csysMatrix = new double[8];
double[][] transform = new double[3][];
transform[0] = new double[3];
transform[1] = new double[3];
transform[2] = new double[3];
transform[3] = new double[3];

foreach (Component comp in arrAllComponents)
{
    // To Get the component Path information
     the_UFSESSION.Assem.AskComponentData(comp.Tag, out sPartName, out sRefSetName, out sInstanceNameOfPart, out origin, out csysMatrix, out transform);
}

 

I want to get the path of the component (Loaded or Not Loaded) .

Tried component.prototype.owningpart.fullpath but it gives error if the part is not in the SearchDirectories folders defined in Assembly load options.

 

 

Regards,

Maddy

Windows 7 x64
NX 8.5, NX 9.0. And also NX 7.5
Visual Studio 2010 SP1, 2012 Update 4
8 REPLIES

Re: UFSession.Assem.AskComponentData Error

Legend
Legend

If I have it correct you first need to get the instant part of the component (in vb)

 

Dim theInst As NXOpen.Tag = ufs.Assem.AskInstOfPartOcc(child.Tag)

 

then ensure that it is loaded

 

ufs.Assem.EnsureChildLoaded(theInst, loadStatus1)

 

 

Then you should be able get the component part data

 

Regards  Frank Swinkels

Re: UFSession.Assem.AskComponentData Error

Pioneer
Pioneer

Hi Frank

 

In Assembly Load options there were three options.
       1. From Saved
       2. From Folder
       3. From Search Folders

The second option is default to load an assembly file.

Case 1:

MainAssemblyFile (D:\NXFiles\Test\MainAssemblyFile.prt)
	|-> Part_1    (D:\NXFiles\Test\Part_1.prt)
	|-> Part_2    (D:\NXFiles\Test\Part_2.prt)
	|-> Part_3    (D:\NXFiles\Test\Part_3.prt)
	|-> Assembly_1    (D:\NXFiles\Test\Assembly_1.prt)
			|-> SubPart_1    (D:\NXFiles\Test\SubPart_1.prt)

All components in the MainAssemblyFile were present in the same folder,
When we open the MainAssemblyFile, all Components under this will be loaded automatically.

Case 2:

MainAssemblyFile (D:\NXFiles\Test\MainAssemblyFile.prt)
	|-> Part_1    (D:\NXFiles\Test\Part_1.prt)
	|-> Part_2    (D:\NXFiles\Test\Part_2.prt)
	|-> Part_3    (D:\NXFiles\Test\Part_3.prt)
	|-> Assembly_1    (D:\NXFiles\Assembly_1.prt)
			|-> SubPart_1    (D:\NXFiles\SubPart_1.prt)

In This case Part_1,Part_2,Part_3 were present in "D:\NXFiles\Test" so will automatically loaded by NX.

Where as Assembly_1,SubPart_1 were not loaded, as they are not present in "D:\NXFiles\Test" or the subdirectories inside "D:\NXFiles\Test"

So if i can able to get the filepath information (like what we get from theSession.Parts.Work.FullPath), then i can set the searchDirectories in

 

theSession.Parts.LoadOptions.SetSearchDirectories 

Once I set the directories, I can able to load all the components and work with.

Is there any other alternative way to achive this?

Thanks and Regards,
Maddy

 

 

Windows 7 x64
NX 8.5, NX 9.0. And also NX 7.5
Visual Studio 2010 SP1, 2012 Update 4

Re: UFSession.Assem.AskComponentData Error

Phenom
Phenom

The transform matrix definition looks a bit odd to me. The function is expecting a 2 dimensional array and it looks like you are giving it an array of arrays. I think it should be:

 

string sPartName = null;
string sRefSetName = null;
string sInstanceNameOfPart = null;
double[] origin = new double[2] ;
double[] csysMatrix = new double[8];
double[,] transform = new double[3,3];

foreach (Component comp in arrAllComponents)
{
    // To Get the component Path information
     the_UFSESSION.Assem.AskComponentData(comp.Tag, out sPartName, out sRefSetName, out sInstanceNameOfPart, out origin, out csysMatrix, out transform);
}

 

Re: UFSession.Assem.AskComponentData Error

Phenom
Phenom

I have a "LoadComponent" function that I often use. Below is the portion that uses the .AskComponentData function. The code is in VB syntax.

 

    Private Function LoadComponent(ByVal theComponent As Component) As Boolean

        Dim thePart As Part = theComponent.Prototype.OwningPart

        Dim partName As String = ""
        Dim refsetName As String = ""
        Dim instanceName As String = ""
        Dim origin(2) As Double
        Dim csysMatrix(8) As Double
        Dim transform(3, 3) As Double

        Try
            If thePart.IsFullyLoaded Then
                'component is fully loaded
            Else
                'component is partially loaded
            End If
            lg.WriteLine("  component: " & theComponent.DisplayName & " is already partially or fully loaded")
            lg.WriteLine("  return: True")
            lg.WriteLine("exiting Sub LoadComponent()")
            lg.WriteLine("")
            Return True
        Catch ex As NullReferenceException
            'component is not loaded
            Try
                lg.WriteLine("  component not loaded, retrieving part information")
                _theUfSession.Assem.AskComponentData(theComponent.Tag, partName, refsetName, instanceName, origin, csysMatrix, transform)
                lg.WriteLine("  component part file: " & partName)

                Dim theLoadStatus As PartLoadStatus
                _theSession.Parts.Open(partName, theLoadStatus)
.
.
.

Re: UFSession.Assem.AskComponentData Error

Pioneer
Pioneer

Hi cowski,

 

I did tried the same, but could able to get it work, but what i want is to load a file which is not present in the folders defined in Assembly Load Options.

 

I need to get the component.prototype's path info i.e. Component.Prototype.OwningPart.FullPath from the assembly file opened.

 

Could you tel me is it not possible to get the FullPath of a component when the component is not loaded as it is not present in the directories mentioned in Assembly Load Options.

 

i hope i have explained it better in my reply to Frank, 

 

 

Thanks and Regards,

 

Windows 7 x64
NX 8.5, NX 9.0. And also NX 7.5
Visual Studio 2010 SP1, 2012 Update 4

Re: UFSession.Assem.AskComponentData Error

Pioneer
Pioneer

Here is the image which we get if the file we are trying to load is not present in the folders defined in Assembly Load Options.

 

NXPart Load Error .JPG

 

 

Thanks and Regards,

Maddy

 

Windows 7 x64
NX 8.5, NX 9.0. And also NX 7.5
Visual Studio 2010 SP1, 2012 Update 4

Re: UFSession.Assem.AskComponentData Error

Phenom
Phenom

Would the "as-saved" option work for you? Using the .AskAssemOptions and .SetAssemOptions methods, you could change the load option to "as-saved" before attempting to load the component(s). Alternately, you could shell out to one of the command line utilities (such as ugpc.exe or ug_edit_part_names.exe) to find the full path to the components.

 

If the component file has been moved with OS commands (moving the file to a different directory with the windows explorer as opposed to doing a "save-as" in NX), then NX won't be any help because it no longer knows where to find the file. In this case, you could use commands to search the computer's file system for the given part name.

Re: UFSession.Assem.AskComponentData Error

Pioneer
Pioneer

Thanks Cowski,

 

"As Saved" option worked. I dont know why i didnt tried with this option.

Now i can load all components and get the path info.

 

Regards,

Maddy

Windows 7 x64
NX 8.5, NX 9.0. And also NX 7.5
Visual Studio 2010 SP1, 2012 Update 4