copying assembly sketch to component

copying assembly sketch to component

tmathieson
Advocate Advocate
432 Views
4 Replies
Message 1 of 5

copying assembly sketch to component

tmathieson
Advocate
Advocate

Hello to All,

 

 i am trying to copy a sketch from an assembly into the piece parts in the assembly.  i can copy the sketch into the part(s), but am having issues with the proper  proxies.  have searched the forums, found some helpful info (and code, thank you!), but still can't figure it out.

 

Sub Main()
	Dim oDoc As Document
	oDoc = ThisDoc.Document
	Dim oAsmCD As AssemblyComponentDefinition
	oAsmCD = oDoc.ComponentDefinition
	Dim oObjToDelete As Object
	Dim oTo As TransientObjects= ThisApplication.TransientObjects
    Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oAsmCompDef As AssemblyComponentDefinition = ThisServer.ActiveDocument.ComponentDefinition
	Dim oSketch1 As PlanarSketch 
	Try
		oSketch1  = oAsmCompDef.Sketches("Sketch 1")
	Catch EX As Exception
		Logger.Debug("COULD NOT FIND SKETCH")
	End Try
	Dim oSketchPartA_Proxy As PlanarSketchProxy

	Dim oOcc As ComponentOccurrence
	'oAsmCompDef.CreateGeometryProxy(oSketch1, oSketchPartA_Proxy)
	
	Dim oSketch2 As PlanarSketch '= oOcc.Definition.Sketches("BEVEL_CUT")
	For Each oOcc In oAsmCompDef.Occurrences
		Logger.Debug(oOcc.Name)
		Dim oOccPartB As ComponentOccurrence = oAsmCompDef.Occurrences.ItemByName(oOcc.Name)
		Dim oPartB_Def As PartComponentDefinition = oOccPartB.Definition
		Dim oSketchPartB As PlanarSketch = oPartB_Def.Sketches.Add(oPartB_Def.WorkPlanes.Item(2), False)
		Try
			oSketch2 = oOcc.Definition.Sketches("BEVEL_CUT")
			oSketchPartB = oSketch2
		Catch ex As Exception
'			Dim oOccPartB As ComponentOccurrence = oAsmCompDef.Occurrences.ItemByName(oOcc.Name)
'			Dim oPartB_Def As PartComponentDefinition = oOccPartB.Definition
			Logger.Debug("sketch not found")
			oSketchPartB = oPartB_Def.Sketches.Add(oPartB_Def.WorkPlanes.Item(2), False)
			oSketchPartB.Name = "BEVEL_CUT"
		End Try
	        Dim oSketchPartB_Proxy As PlanarSketchProxy
	        oOccPartB.CreateGeometryProxy(oSketchPartB, oSketchPartB_Proxy)
			

        'oSketchPartA_Proxy.CopyContentsTo(oSketchPartB_Proxy)


			Try
				oSketch2 = oOcc.Definition.Sketches("BEVEL_CUT")
				Call oSketch1.CopyContentsTo(oSketchPartB_Proxy)
				Logger.Debug("sketch....2")
			Catch EX As Exception
				Logger.Debug("NO SKETCH IN MODEL...." & oOcc.Name)
			End Try
		
		'Call oSketch1.CopyContentsTo(oSketch2)
	Next
End Sub

 

i have attached a zip with my test file, with the ilogic rule in the assembly, and here is my source code.  I have commented out this line as i get an error

 

'oAsmCompDef.CreateGeometryProxy(oSketch1, oSketchPartA_Proxy)

 

any help, as  always, would be greatly appreciated!!

 

thanks in advance!!

0 Likes
Accepted solutions (1)
433 Views
4 Replies
Replies (4)
Message 2 of 5

A.Acheson
Mentor
Mentor

Hi @tmathieson 

In order to work on the parts sketch from the assembly you need to create a proxy for the sketch. See below 

Sub Main()
	
	Dim oDoc As Document = ThisDoc.Document
	Dim oAsmCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
	Dim oAsmSketch As PlanarSketch 
	Dim ex As Exception
	
	Try
		oAsmSketch = oAsmCompDef.Sketches("Sketch 1")
	Catch ex 
		Logger.Debug("COULD NOT FIND SKETCH")
		Exit Sub
	End Try
	
	Dim oPartSketch As PlanarSketch
	Dim oPartSketchProxy As PlanarSketchProxy

	For Each oOcc As ComponentOccurrence In oAsmCompDef.Occurrences.AllLeafOccurrences
		Logger.Debug(oOcc.Name)
		
		Dim oOccDef As PartComponentDefinition = oOcc.Definition
		Dim oOccDoc As PartDocument = oOccDef.Document
		
		If Not oOccDoc.IsModifiable Then Continue For
	
		Try
			oPartSketch = oOccDef.Sketches("BEVEL_CUT")
		Catch ex 
			Logger.Debug("sketch not found! Adding")
			oPartSketch = oOccDef.Sketches.Add(oOccDef.WorkPlanes.Item(2), False)
			oPartSketch.Name = "BEVEL_CUT"
			Try
				oOcc.CreateGeometryProxy(oPartSketch, oPartSketchProxy)
				oAsmSketch.CopyContentsTo(oPartSketchProxy)
			Catch ex 
				Logger.Debug("Problems copying Sketch...." & oOcc.Name)
			End Try
		End Try
		
	Next
End Sub

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 5

tmathieson
Advocate
Advocate

Hi @A.Acheson ,  thanks so much for looking at this.  it's getting me in the right direction, but still not there yet.  i have copied/pasted your code into the attached assembly (Revised - Sep12-23),  and it copies the sketch into the part, but they are still not translating right...when i run the rule, the sketches show up as shown in the part files.  what i need is for the sketch to translate to the relative positions in the part, so that in this picture, all sketch would be superimposed on top of each other, and we would  only see 1 sketch, not 6

tmathieson_0-1694693061006.png

 

maybe I need a matrix and another Proxy?

 

again, thanks for your help on this, it is much appreciated!!

 

0 Likes
Message 4 of 5

A.Acheson
Mentor
Mentor

So you need to position the sketch in the part file. This can be tricky, you will need to pick up the part position in the assembly it's proxy and then move the sketch over the required offset in the part itself. I haven't done this operation before so don't have a sample but I would start with getting the sketch position in the assembly first. 

 

This should be the starting point. 

Syntax

PlanarSketch.OriginPointGeometry() As Point

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

tmathieson
Advocate
Advocate
Accepted solution

Morning @A.Acheson ,

 

Again, thanks for your help on this. so, after digging some more into the Forums and other sources, I could not find a way to 'proxy' my assembly sketch down into my piece parts.  it seems like there should be a way to do this, but I can't find a way....

 

it seems, to me, that proxies only are applicable to components within the assembly and not to the assembly itself?

so, with help from @WCrihfield and @ssyXENBT posts (thanks!!), I have taken the approach of creating the sketch in a part file, then using proxies to A>  proxy project the sketch from the source part to the assembly, and B> proxy to project the sketch from A proxy to into the destination part(s). this projects the sketch in the proper place /orientation, which I can then use to cut the parts..... a bit of a twist but creates the desired results...

 

 

i was hoping i could find a more straight forward solution, i.e. proxy the assembly sketch down into the component, but this does work....

I've attached the sample here, rule to run is "Revised - Sep15-23-part to part".....

again, thanks for your

 

0 Likes