Calling the main Assembly and its copy without changing the main Assembly

Calling the main Assembly and its copy without changing the main Assembly

mohnish_soral
Explorer Explorer
232 Views
1 Reply
Message 1 of 2

Calling the main Assembly and its copy without changing the main Assembly

mohnish_soral
Explorer
Explorer

mohnish_soral_0-1692352193251.png

In the above figure I am placing the door at location read by my Json file using Inventor API

The parts are placed at the location lets say C:\abc\def , so I call the main part and then create the copy of that part by the code shown below , now in this file path mention above I have the door assembly folder in which door and its assembly is placed which then called and get placed as we can see in above figure.

Code is :

 

foreach (var entry in parameters) // Variable entry is created and the JSON data gets asssign one by one to it
{
string partName = entry.Key; // Part name inorder to pass it to string and run in common loop
List<ComponentOccurrence> componentList = new List<ComponentOccurrence>();
int index = 0;
string location;

if (files_component.Contains(partName + ".ipt"))
{
location = IOPath.Combine(inputFilesDir, partName + ".ipt"); // this is used to open the file in input directory
}
else
{
location = IOPath.Combine(inputFilesDir, partName + "_assembly\\" + partName + ".iam"); // this is used to open the door.iam files in the input directory
}
foreach (var componentData in entry.Value) // It takens the value and pass it to component data and that starts assigning values to transformation matrix
{
Matrix transformationMatrix = TransformationMatrix(componentData); // transformation matrix is taken from Matrix creation
ComponentOccurrence componentOccurrence = null;
if (index == 0)
{
componentOccurrence = asmDoc.ComponentDefinition.Occurrences.Add(location, transformationMatrix); //Placing the original part firstly and then moving to else part for create copy method
componentList.Add(componentOccurrence);
document = (Document)componentOccurrence.Definition.Document;
}
else // It is use to create the copy after first part is place
{
componentOccurrence = create_copy_component(asmDoc, transformationMatrix, componentList[0], partName + index.ToString(), location); // it creates the copy of the component and then place in Inventor
document = (Document)componentOccurrence.Definition.Document;

}

}

private ComponentOccurrence create_copy_component(AssemblyDocument asmDoc, Matrix oPositionMatrix, ComponentOccurrence Component_, string name, string location)
{
Document partdoc = (Document)Component_.Definition.Document;

String CopiedFile ;
var docType = partdoc.DocumentType;

switch (docType)
{
case DocumentTypeEnum.kAssemblyDocumentObject:
var asm = partdoc as AssemblyDocument;
CopiedFile = name + ".iam";
break;

case DocumentTypeEnum.kPartDocumentObject:
var ipt = partdoc as PartDocument;
CopiedFile = name + ".ipt";
break;

default:
throw new ApplicationException(string.Format("Unexpected document type ({0})", docType));
}
String OrigFile = partdoc.FullFileName;
var component_dir = System.IO.Path.GetDirectoryName(OrigFile);// path to original file
// path to copied file
string Part_Path_copy_1 = System.IO.Path.Combine(component_dir, CopiedFile);
try
{
System.IO.File.Delete(Part_Path_copy_1); // use to delete the exisiting parts in the present directory
}
catch (IOException)
{
Console.WriteLine("The specified file is in use. It might be open by Inventor");
}
inventor_app.FileManager.CopyFile(location, Part_Path_copy_1, FileManagementEnum.kCopyFileMask); // API for the copied part and the return of that documnet which can be used in the above functions
ComponentOccurrence Copy_part = asmDoc.ComponentDefinition.Occurrences.Add(Part_Path_copy_1, oPositionMatrix) as ComponentOccurrence;
return Copy_part;
}

 

mohnish_soral_1-1692352266980.png

Now my question is when I change the json file and want that the door file should be placed twice instead of one

the first door gets placed perfectly , but as soon as the second door get placed , both the door changes their dimension

The first door converts itself two seconf door as seen in figure

Why this is so
Is this because I am using the same parts between the components
What can be the solutions ?
I have to also create the copy of that copy door parts if yes , so how can that door can recognized I have to take the copy parts only

Can someone please take me out from this

Thank you in advance

0 Likes
233 Views
1 Reply
Reply (1)
Message 2 of 2

A.Acheson
Mentor
Mentor

Hi @mohnish_soral 

For future reference this should be posted in the Ilogic/Vba forum as its a coding question. 

 

From your description it sounds like you have placed the exact same part but you intended to have too seperate parts. If you want to have two seperate parts Perform a save as from inventor and then place the part. Check the filepaths. Don't perform any renaming in windows, the API has all the functions available.  

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes