iLogic Copy Blocks part to part

iLogic Copy Blocks part to part

dusan.naus.trz
Advisor Advisor
780 Views
3 Replies
Message 1 of 4

iLogic Copy Blocks part to part

dusan.naus.trz
Advisor
Advisor

I searched for this function in Inventor, I did not find any import of blocks from files. I didn't find anything on the forum either.

 

Question: Is it possible using ilogic?

1. I need to copy 1 block named ROWS_poz_01 from RoWS.ipt file to Shaft ipt file

2. I need to copy all the blocks from the RoWS.ipt file to the Shaft ipt file

 

 

0 Likes
Accepted solutions (1)
781 Views
3 Replies
Replies (3)
Message 2 of 4

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @dusan.naus.trz 

I wrote this simple CopyBlocks sub for you.

First argument is the document to copy the blocks from.

Second argument is the document to copy the blocks to.

Third argument is the name of the block you want to copy. If you don't enter anything here all blocks will be copied.

 

See example below 🙂

Sub Main
	'Document to copy from
	Dim oDoc As PartDocument = ThisApplication.Documents.Open("C:\Temp\CopyBlocks\ROWS.ipt", False)
	
	'Call sub - if you add a name as third argument then only that block will be copied, otherwise every block will be copied
	CopyBlocks(oDoc, ThisDoc.Document, "ROWS_poz_01")
End Sub

Sub CopyBlocks(fromDoc As Document, toDoc As Document, Optional oName As String = "")
	If oName <> ""
		fromDoc.ComponentDefinition.SketchBlockDefinitions.Item(oName).CopyTo(toDoc)
	Else
		For Each oBlock As SketchBlockDefinition In fromDoc.ComponentDefinition.SketchBlockDefinitions
			oBlock.CopyTo(toDoc)
		Next
	End If
End Sub
Message 3 of 4

dusan.naus.trz
Advisor
Advisor

Hello, thank you very much. It works great.

Message 4 of 4

dimamazutaMMJ32
Advocate
Advocate

Hello. Is there a way to copy a sketch from different part to opened file?

0 Likes