Create Copy with ilogic

Create Copy with ilogic

jam_bhatti
Enthusiast Enthusiast
3,772 Views
23 Replies
Message 1 of 24

Create Copy with ilogic

jam_bhatti
Enthusiast
Enthusiast

 

I have done a Vessel Nozzle with options as sub assembly and need to create a clone at same location with all constraints.

is it possible by ilogic rule.

mean just click copy button on form and create same nozzle at current spot. then i move to another locations to create other nozzle with different sizes.

 

 

Copy Nozzle.jpg

 

 

 

0 Likes
Accepted solutions (1)
3,773 Views
23 Replies
Replies (23)
Message 2 of 24

jam_bhatti
Enthusiast
Enthusiast

i am waiting response from forum. any comment.

Is it difficult to do or not possible?

 

0 Likes
Message 3 of 24

rossano_praderi
Collaborator
Collaborator
Hi,
is possible and is not so difficult, but it take time.
Every person who is writing in this forum are doing it for free.
Then if you want answers, please be patient.

Bregs
Rossano Praderi


--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
0 Likes
Message 4 of 24

MechMachineMan
Advisor
Advisor

Have you thought of using iMates/Place iLogic component to accomplish the same thing?


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 5 of 24

jam_bhatti
Enthusiast
Enthusiast

@MechMachineMan

 

Every time make a copy then place the exact location, these thing taking much time. so i want it by rule to save time.

 

0 Likes
Message 6 of 24

Balaji_Ram
Alumni
Alumni

Hi,

 

Have you tried creating the assembly occurrence directly as in this code snippet ?

 

doc = ThisDoc.Document

Dim oAssyDoc As AssemblyDocument
oAssyDoc = doc

Dim oDef As AssemblyComponentDefinition
oDef = oAssyDoc.ComponentDefinition

Dim oOcc As ComponentOccurrence
oMatrix = ThisApplication.TransientGeometry.CreateMatrix() 
	
oOcc = oDef.Occurrences.Item(1)

Call oAssyDoc.ComponentDefinition.Occurrences.Add(oOcc.Definition.Document.FullFileName, oMatrix)     
oAssyDoc.Activate

Regards,

Balaji

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 7 of 24

MechMachineMan
Advisor
Advisor
Ok. But if you use iMates properly, you can just insert a new part and have it snap to the base plate thorough iMate, and then select it's location on the Grid of Planes again, using imates and just selecting those.

iMates can also be manipulated through the API as well so that's what I mean by you being able to speed it all up. Rather than placing a copy, selecting the constrain you want to modify to change it's location, then saving that.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 8 of 24

jam_bhatti
Enthusiast
Enthusiast

@Balaji_Ram

 

Hi

Thanks for making this code, but i need the unique copy of assembly. the code creates assembly with same perameters and part names.

second things assembly having some parts as suppressed so need to be ignore these during copying.

please help me more about that.

 

SyntaxEditor Code Snippet

doc = ThisDoc.Document

Dim oAssyDoc As AssemblyDocument
oAssyDoc = doc

Dim oDef As AssemblyComponentDefinition
oDef = oAssyDoc.ComponentDefinition

Dim oOcc As ComponentOccurrence
oMatrix = ThisApplication.TransientGeometry.CreateMatrix() 
oTG = ThisApplication.TransientGeometry    
oOcc = oDef.Occurrences.Item(9)
oMatrix.SetTranslation(oTG.CreateVector(0, (NELV-SF)/10, 0))

Call oAssyDoc.ComponentDefinition.Occurrences.Add(oOcc.Definition.Document.FullFileName, oMatrix)     
oAssyDoc.Activate

 

 

 

0 Likes
Message 9 of 24

Balaji_Ram
Alumni
Alumni

Hi,

 

Here are the steps to keep the sub-assembly independent when creating a new occurrence.

 

1. Ensure that all the parts in the sub-assembly are saved using a different part file name.


2. Replace all the parts in the sub-assembly and ensure they refer to the new part files created in step-1.

    In the Inventor UI, you would do this using Component->Replace


3. Save the modified sub-assembly as a different assembly file.


4. Create a sub-occurrence using the new modified sub-assembly.

 

This should ensure that the changes to the part files will not get propagated for all the sub-assemblies.

 

I haven't put them all together yet, but here are the individual parts to do the steps.

Hope this gives you some direction in the meantime.

 

For saving the sub-assembly :

 

Dim oAssyDoc As AssemblyDocument
oAssyDoc = doc

Dim oDef As AssemblyComponentDefinition
oDef = oAssyDoc.ComponentDefinition

Dim oSubAssy As ComponentOccurrence
oSubAssy = oDef.Occurrences.Item(2)

Dim oSubAssyDef As AssemblyComponentDefinition 
oSubAssyDef = oSubAssy.Definition

Dim oSubAssyDoc As AssemblyDocument
oSubAssyDoc = oSubAssyDef.Document

oSubAssyDoc.SaveAs("D:\Temp\MyNewSubAssy.iam", True)

 

For saving the parts in a sub-assembly 

 

Dim i As Integer
i = 1
' Save the parts in the sub-assembly with a different file name.
For Each oOcc In oSubAssyOcc.SubOccurrences
	If (oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject) Then
		Dim oPartPath As String 
		oPartPath = oOcc.Definition.Document.FullFileName 
		MessageBox.Show(UCase(oOcc.Name) & " : " & oPartPath)
		oOcc.Definition.Document.SaveAs("D:\" & i & ".ipt", True)
	End If
	i = i + 1
Next

 

For replacing the parts in the sub-assembly :

 

 ' Replace the parts in the new sub-assembly with the newly created ones

i = 1
Dim oDef1 As AssemblyComponentDefinition
oDef1 = oSubAssyDoc1.ComponentDefinition
For Each oOcc In oDef1.Occurrences
	If (oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject) Then
		Dim oPartPath As String 
		oPartPath = oOcc.Definition.Document.FullFileName 
		MessageBox.Show(UCase(oOcc.Name) & " : " & oPartPath)
		oOcc.Replace("D:\" & i & ".ipt", True)
	End If
	i = i + 1
Next
oSubAssyDoc1.SaveAs("D:\MyNewSubAssy.iam", False)

 

 

 For creating a new occurrence using the sub-assembly

 

' Load the modified sub-assembly 
oMatrix = ThisApplication.TransientGeometry.CreateMatrix() 
oTG = ThisApplication.TransientGeometry
oMatrix.SetTranslation(oTG.CreateVector(0, (NELV-SF)/10, 0))

Call oAssyDoc.ComponentDefinition.Occurrences.Add("D:\MyNewSubAssy.iam", oMatrix)     
oAssyDoc.Activate

Regards,

Balaji

 



Balaji
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 10 of 24

jam_bhatti
Enthusiast
Enthusiast

@Balaji_Ram

 

Hi

For saving the sub-assembly, code creates the whole main assembly. how can i assign to saveas target subassembly.

i am not expert in coding and can't fix it between other steps also. could you favor me to combine all things with test sub-assembly.

i will highly appriciate to help me and really helpfull in my project.

 

Best Regard's

 

Jamil

 

 

0 Likes
Message 11 of 24

Balaji_Ram
Alumni
Alumni

Hi Jamil,

 

Does this code snippet help ? It should create a new occurrence based on a sub-assembly. The new sub-assembly occurrence will refer to the copy of the part files, so can be modified independently. 

 

In the code snippet, i am assuming that the first occurrence is a sub-assembly. You may need to tweak to suit your needs.

 

doc = ThisDoc.Document

Dim oAssyDoc As AssemblyDocument
oAssyDoc = doc

Dim oAssyDef As AssemblyComponentDefinition
oAssyDef = oAssyDoc.ComponentDefinition

Dim oSubAssyOcc As ComponentOccurrence 
oSubAssyOcc = oAssyDef.Occurrences(1)

Dim newPartPath As String
Dim newSubAssyPath As String
	
If (oSubAssyOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject) Then

	Dim oSubAssyDef As AssemblyComponentDefinition
	oSubAssyDef = oSubAssyOcc.Definition

	Dim oSubAssyDoc As AssemblyDocument 
	oSubAssyDoc = oSubAssyDef.Document

	If (System.IO.File.Exists(oSubAssyDoc.FullFileName)) Then
		Dim fi As New System.IO.FileInfo(oSubAssyDoc.FullFileName)
		newSubAssyPath = System.IO.Path.Combine(New System.String() {fi.DirectoryName, fi.Name.Replace(fi.Extension, [String].Format("_New{0}", fi.Extension))})
	End If
			
    System.IO.File.Copy(oSubAssyDoc.FullFileName, newSubAssyPath, True)
    
	If (System.IO.File.Exists(newSubAssyPath) = False) Then
		MessageBox.Show(String.Format("Error copying the SubAssembly file {0}", oSubAssyDoc.FullFileName))
		Return
	End If
			
	' Create a copy Of the all the parts in the Sub-Assembly
	Dim oSubOcc As ComponentOccurrence
	For Each oSubOcc In oSubAssyOcc.SubOccurrences
		If (oSubOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject) Then
			Dim oPartDef As PartComponentDefinition 
			oPartDef = oSubOcc.Definition 
				
			Dim oPartDoc As PartDocument 
			oPartDoc = oPartDef.Document
			
			If (System.IO.File.Exists(oPartDoc.FullFileName)) Then
				Dim fi As New System.IO.FileInfo(oPartDoc.FullFileName)
				newPartPath = System.IO.Path.Combine(New System.String() {fi.DirectoryName, fi.Name.Replace(fi.Extension, [String].Format("_New{0}", fi.Extension))})
			End If
			
			System.IO.File.Copy(oPartDoc.FullFileName, newPartPath, True)
			
			If (System.IO.File.Exists(newPartPath) = False) Then
				MessageBox.Show(String.Format("Error copying the part file {0}", oPartDoc.FullFileName))
				Return
			End If
	
		ElseIf (oSubOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject) Then
			MessageBox.Show(String.Format("SubAssembly {0} inside a SubAssembly. This case is not yet handled.", oSubOcc.Name))
			Return
		End If
	Next
	
	' Create a New occurrence Of the Sub-Assembly
    Dim oPosition As Matrix 
	oPosition = ThisApplication.TransientGeometry.CreateMatrix() 
    
	Dim oNewSubAssyOcc As ComponentOccurrence 
	oNewSubAssyOcc = oAssyDoc.ComponentDefinition.Occurrences.Add(newSubAssyPath, oPosition)
	
    ' Replace the parts in the New Sub-Assembly 
	For Each oSubOcc In oNewSubAssyOcc.SubOccurrences
		If (oSubOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject) Then
			Dim oPartDef As PartComponentDefinition 
			oPartDef = oSubOcc.Definition
            z
			Dim oPartDoc As PartDocument 
			oPartDoc = oPartDef.Document
            
		  	If (System.IO.File.Exists(oPartDoc.FullFileName)) Then
				Dim fi As New System.IO.FileInfo(oPartDoc.FullFileName)
				newPartPath = System.IO.Path.Combine(New System.String() {fi.DirectoryName, fi.Name.Replace(fi.Extension, [String].Format("_New{0}", fi.Extension))})
			End If
			
			If (System.IO.File.Exists(newPartPath)) Then
            	oSubOcc.Replace(newPartPath, True)
			End If
				
		End If
	Next
ElseIf (oSubAssyOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject) Then
	MessageBox.Show("Sorry, Expecting a subassembly to copy, but found " & UCase(oSubAssyOcc.Name))
End If

Regards,

Balaji

 

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Message 12 of 24

jam_bhatti
Enthusiast
Enthusiast

@Balaji_Ram

Hi,

Your code snippet working superb for first attempt. but second copy make similar to the first copy. i am trying to check with different scenario with my subassembly and will provide with (screenshots/video) feed back shortly.

 

Thanks and best Regard's

 

Jamil

0 Likes
Message 13 of 24

Balaji_Ram
Alumni
Alumni

Hi Jamil,

 

You may need to check the names with which the parts get saved from the earlier occurrence and get replaced in the new sub-assembly occurrence.

 

In the code snippet that i shared, i have simply appended "_New" to the part file names. So, this may be overwriting the part files that get created in the first copy. I haven't ensured that the new part/assembly file names are unique. You may need to tweak it to ensure that the file names are as per your naming conventions and unique.

 

Regards,

Balaji

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 14 of 24

jam_bhatti
Enthusiast
Enthusiast

@Balaji_Ram

 

Hi,

Yes the sub-assembly and part created unique for first occurrence and more sub-assemblies occurrences i have to do some steps manually as below:

 

1) change parameters for sub-assembly to getting new location and size. close model with save.

 

2) open Model> go to rule> find and replace the file name "_New{0}" to "_New1{0}" Then  click OK

 

for every new unique occurrence needs these above steps. if its by code it will be smooth compliance.

 

Thanks

 

Add Nozzle.jpg

0 Likes
Message 15 of 24

Balaji_Ram
Alumni
Alumni

Hi Jamil,

 

I do not understand the first manual step that you mentioned.

 

But the second one which requires new file names to be generated automatically can be achieved quite easily.

 

If (System.IO.File.Exists(oSubAssyDoc.FullFileName)) Then
		Dim fi As New System.IO.FileInfo(oSubAssyDoc.FullFileName)
		newSubAssyPath = System.IO.Path.Combine(New System.String() {fi.DirectoryName, fi.Name.Replace(fi.Extension, [String].Format("_New{0}", fi.Extension))})
		
		Dim cnt As Integer
		cnt = 1
		While System.IO.File.Exists(newSubAssyPath) = True
			newSubAssyPath = System.IO.Path.Combine(New System.String() {fi.DirectoryName, fi.Name.Replace(fi.Extension, [String].Format("_New{0}{1}", cnt, fi.Extension))})
			cnt = cnt + 1
		End While
		
		MessageBox.Show(newSubAssyPath)
		
	End If

Regards,

Balaji



Balaji
Developer Technical Services
Autodesk Developer Network

Message 16 of 24

jam_bhatti
Enthusiast
Enthusiast

@Balaji_Ram

 

YES THANKS ITS WORKING FINE NOW.

 

one more thing if you add in this snippet. when disabling some parts in a sub assembly as suppressed. its not woking and encounter the error.

 

I have trying different way but can't resolve.

 

 

doc = ThisDoc.Document

Dim oAssyDoc As AssemblyDocument
oAssyDoc = doc

Dim oAssyDef As AssemblyComponentDefinition
oAssyDef = oAssyDoc.ComponentDefinition

Dim oSubAssyOcc As ComponentOccurrence 
oSubAssyOcc = oAssyDef.Occurrences(9)

If    oSubAssyOcc.Suppressed = True Then
    oSubAssyOcc.Delete
End If
    
Dim newPartPath As String
Dim newSubAssyPath As String

If (oSubAssyOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject) Then


    Dim oSubAssyDef As AssemblyComponentDefinition
    oSubAssyDef = oSubAssyOcc.Definition

    Dim oSubAssyDoc As AssemblyDocument 
    oSubAssyDoc = oSubAssyDef.Document
    
    Dim cnt As String
    cnt = NN

    If (System.IO.File.Exists(oSubAssyDoc.FullFileName)) Then
        Dim fi As New System.IO.FileInfo(oSubAssyDoc.FullFileName)
        newSubAssyPath = System.IO.Path.Combine(New System.String() {fi.DirectoryName, fi.Name.Replace(fi.Extension, [String].Format("_{0}{1}", cnt, fi.Extension))})
    End If
            
    System.IO.File.Copy(oSubAssyDoc.FullFileName, newSubAssyPath, True)
    
    If (System.IO.File.Exists(newSubAssyPath) = False) Then
        MessageBox.Show(String.Format("Error copying the SubAssembly file {0}{1}", oSubAssyDoc.FullFileName))
        Return
    End If
            
    ' Create a copy Of the all the parts in the Sub-Assembly
    Dim oSubOcc As ComponentOccurrence
    For Each oSubOcc In oSubAssyOcc.SubOccurrences
        If (oSubOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject) Then
            Dim oPartDef As PartComponentDefinition 
            oPartDef = oSubOcc.Definition 
                
            Dim oPartDoc As PartDocument 
            oPartDoc = oPartDef.Document
            
            If (System.IO.File.Exists(oPartDoc.FullFileName)) Then
                Dim fi As New System.IO.FileInfo(oPartDoc.FullFileName)
                newPartPath = System.IO.Path.Combine(New System.String() {fi.DirectoryName, fi.Name.Replace(fi.Extension, [String].Format("_{0}{1}", cnt, fi.Extension))})
            End If
            
            System.IO.File.Copy(oPartDoc.FullFileName, newPartPath, True)
            
            If (System.IO.File.Exists(newPartPath) = False) Then
                MessageBox.Show(String.Format("Error copying the part file {0}{1}", oPartDoc.FullFileName))
                Return
            End If
    
        ElseIf (oSubOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject) Then
            MessageBox.Show(String.Format("SubAssembly {0}{1} inside a SubAssembly. This case is not yet handled.", oSubOcc.Name))
            Return
        End If
    Next
    
    ' Create a New occurrence Of the Sub-Assembly
    Dim oPosition As Matrix 
    oPosition = ThisApplication.TransientGeometry.CreateMatrix() 
    oTG = ThisApplication.TransientGeometry
    oPosition.SetTranslation(oTG.CreateVector(0, (NELV-SF)/10, 0))
    
    Dim oNewSubAssyOcc As ComponentOccurrence 
    oNewSubAssyOcc = oAssyDoc.ComponentDefinition.Occurrences.Add(newSubAssyPath, oPosition)
    
    ' Replace the parts in the New Sub-Assembly 
    For Each oSubOcc In oNewSubAssyOcc.SubOccurrences
        If (oSubOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject) Then
            Dim oPartDef As PartComponentDefinition 
            oPartDef = oSubOcc.Definition

            Dim oPartDoc As PartDocument 
            oPartDoc = oPartDef.Document
            
              If (System.IO.File.Exists(oPartDoc.FullFileName)) Then
                Dim fi As New System.IO.FileInfo(oPartDoc.FullFileName)
                newPartPath = System.IO.Path.Combine(New System.String() {fi.DirectoryName, fi.Name.Replace(fi.Extension, [String].Format("_{0}{1}", cnt, fi.Extension))})
            End If
            
            If (System.IO.File.Exists(newPartPath)) Then
                oSubOcc.Replace(newPartPath, True)
            End If
                
        End If
    Next
ElseIf (oSubAssyOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject) Then
    MessageBox.Show("Sorry, Expecting a subassembly to copy, but found " & UCase(oSubAssyOcc.Name))
End If

 

0 Likes
Message 17 of 24

Balaji_Ram
Alumni
Alumni

Hi Jamil,

 

When some of the parts are suppressed, we wont get its definition. So, we can temporarily unsuppress them while copying the parts.

Here is the modified code.

 

   ' Create a copy Of the all the parts in the Sub-Assembly
    Dim oSubOcc As ComponentOccurrence
    For Each oSubOcc In oSubAssyOcc.SubOccurrences
        If (oSubOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject) Then
            Dim oPartDef As PartComponentDefinition 
			
			Dim wasSuppressed As Boolean
            wasSuppressed = False

            If oSubOcc.Suppressed Then
                oSubOcc.Unsuppress()
                wasSuppressed = True
            End If
								
            oPartDef = oSubOcc.Definition 
                
            Dim oPartDoc As PartDocument 
            oPartDoc = oPartDef.Document
            
            If (System.IO.File.Exists(oPartDoc.FullFileName)) Then
                Dim fi As New System.IO.FileInfo(oPartDoc.FullFileName)
                newPartPath = System.IO.Path.Combine(New System.String() {fi.DirectoryName, fi.Name.Replace(fi.Extension, [String].Format("_{0}{1}", cnt, fi.Extension))})
            End If
            
            System.IO.File.Copy(oPartDoc.FullFileName, newPartPath, True)
            
            If (System.IO.File.Exists(newPartPath) = False) Then
                MessageBox.Show(String.Format("Error copying the part file {0}{1}", oPartDoc.FullFileName))
                Return
            End If
			
		 	If wasSuppressed Then
            	oSubOcc.Suppress()
            End If
    
        ElseIf (oSubOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject) Then
            MessageBox.Show(String.Format("SubAssembly {0}{1} inside a SubAssembly. This case is not yet handled.", oSubOcc.Name))
            Return
        End If
    Next

With this, the copied sub-assembly will have all its parts unsuppressed although the sub-assembly from which we copied it had the same parts suppressed. If you choose to suppress the parts even in the new sub-assembly, you can keep track of the part names and suppress them after the copying is done.

 

Hope this helps.

 

Regards,

Balaji

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 18 of 24

jam_bhatti
Enthusiast
Enthusiast

@Balaji_Ram

Hi

Applying the copy rule sub-assembly LOD is going to deactivate and the copy sub-assembly LOD is also deactivated. I don't know why LOD is going to deactivate and how to fix it . due to this i can't able to do finally suppressed parts again using code the end of copy rule snippet.

 

 

If NBL1 = True Then

Component.IsActive(MakePath("Nozzle-01_" & NN & ":1", "Blind-01-01_" & NN & ":1")) = True
Component.IsActive(MakePath("Nozzle-01_" & NN & ":1", "Gasket-01-01_" & NN & ":1")) = True
Else 
Component.IsActive(MakePath("Nozzle-01_" & NN & ":1", "Blind-01-01_" & NN & ":1")) = False
Component.IsActive(MakePath("Nozzle-01_" & NN & ":1", "Gasket-01-01_" & NN & ":1")) = False
End If

 

0 Likes
Message 19 of 24

Balaji_Ram
Alumni
Alumni
Accepted solution

Hi Jamil,

 

I dont see any issue with LOD automatically deactivating. Here is the code that i am using which includes the suppressing of parts that were already suppressed in the sub-assembly being copied.

 

doc = ThisDoc.Document

Dim oAssyDoc As AssemblyDocument
oAssyDoc = doc

Dim oAssyDef As AssemblyComponentDefinition
oAssyDef = oAssyDoc.ComponentDefinition

Dim oSubAssyOcc As ComponentOccurrence 
oSubAssyOcc = oAssyDef.Occurrences(1)

If    oSubAssyOcc.Suppressed = True Then
    oSubAssyOcc.Delete
End If
    
Dim newPartPath As String
Dim newSubAssyPath As String

If (oSubAssyOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject) Then

    Dim oSubAssyDef As AssemblyComponentDefinition
    oSubAssyDef = oSubAssyOcc.Definition

    Dim oSubAssyDoc As AssemblyDocument 
    oSubAssyDoc = oSubAssyDef.Document
    
    Dim cnt As String
    cnt = NN

    If (System.IO.File.Exists(oSubAssyDoc.FullFileName)) Then
        Dim fi As New System.IO.FileInfo(oSubAssyDoc.FullFileName)
        newSubAssyPath = System.IO.Path.Combine(New System.String() {fi.DirectoryName, fi.Name.Replace(fi.Extension, [String].Format("_{0}{1}", cnt, fi.Extension))})
    End If
            
    System.IO.File.Copy(oSubAssyDoc.FullFileName, newSubAssyPath, True)
    
    If (System.IO.File.Exists(newSubAssyPath) = False) Then
        MessageBox.Show(String.Format("Error copying the SubAssembly file {0}{1}", oSubAssyDoc.FullFileName))
        Return
    End If
          
	Dim oList As Collection = New Collection
			
    ' Create a copy Of the all the parts in the Sub-Assembly
    Dim oSubOcc As ComponentOccurrence
    For Each oSubOcc In oSubAssyOcc.SubOccurrences
        If (oSubOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject) Then
            Dim oPartDef As PartComponentDefinition 
			
			Dim wasSuppressed As Boolean
            wasSuppressed = False

            If oSubOcc.Suppressed Then
                oSubOcc.Unsuppress()
                wasSuppressed = True
            End If
								
            oPartDef = oSubOcc.Definition 
                
            Dim oPartDoc As PartDocument 
            oPartDoc = oPartDef.Document
            
            If (System.IO.File.Exists(oPartDoc.FullFileName)) Then
                Dim fi As New System.IO.FileInfo(oPartDoc.FullFileName)
                newPartPath = System.IO.Path.Combine(New System.String() {fi.DirectoryName, fi.Name.Replace(fi.Extension, [String].Format("_{0}{1}", cnt, fi.Extension))})
            End If
            
            System.IO.File.Copy(oPartDoc.FullFileName, newPartPath, True)
            
            If (System.IO.File.Exists(newPartPath) = False) Then
                MessageBox.Show(String.Format("Error copying the part file {0}{1}", oPartDoc.FullFileName))
                Return
            End If
			
		 	If wasSuppressed Then
				oList.Add(newPartPath)
            	oSubOcc.Suppress()
            End If
    
        ElseIf (oSubOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject) Then
            MessageBox.Show(String.Format("SubAssembly {0}{1} inside a SubAssembly. This case is not yet handled.", oSubOcc.Name))
            Return
        End If
    Next
    
    ' Create a New occurrence Of the Sub-Assembly
    Dim oPosition As Matrix 
    oPosition = ThisApplication.TransientGeometry.CreateMatrix() 
    oTG = ThisApplication.TransientGeometry
    oPosition.SetTranslation(oTG.CreateVector(0, (NELV-SF)/10, 0))
    
    Dim oNewSubAssyOcc As ComponentOccurrence 
    oNewSubAssyOcc = oAssyDoc.ComponentDefinition.Occurrences.Add(newSubAssyPath, oPosition)
    
    ' Replace the parts in the New Sub-Assembly and suppress them if needed
    For Each oSubOcc In oNewSubAssyOcc.SubOccurrences
        If (oSubOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject) Then
            Dim oPartDef As PartComponentDefinition 
            oPartDef = oSubOcc.Definition

            Dim oPartDoc As PartDocument 
            oPartDoc = oPartDef.Document
            
              If (System.IO.File.Exists(oPartDoc.FullFileName)) Then
                Dim fi As New System.IO.FileInfo(oPartDoc.FullFileName)
                newPartPath = System.IO.Path.Combine(New System.String() {fi.DirectoryName, fi.Name.Replace(fi.Extension, [String].Format("_{0}{1}", cnt, fi.Extension))})
            End If
            
            If (System.IO.File.Exists(newPartPath)) Then
                oSubOcc.Replace(newPartPath, True)
            End If
			
			' Suppress if needed
			For Each PartName As String In oList
				If (PartName = newPartPath) Then
					oSubOcc.Suppress()
					Exit For
				End If
			Next
		End If
    Next
ElseIf (oSubAssyOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject) Then
    MessageBox.Show("Sorry, Expecting a subassembly to copy, but found " & UCase(oSubAssyOcc.Name))
End If

Here is a video recording showing the results :

 

http://autode.sk/1HrB50E

 

Regards,

Balaji



Balaji
Developer Technical Services
Autodesk Developer Network

Message 20 of 24

jam_bhatti
Enthusiast
Enthusiast

Hi Balaje,

 

Thanks for help and done great job that cover my needs.

 

Jamil

0 Likes