Trying to project 3Dsketch lines on to a 2D sketch

Trying to project 3Dsketch lines on to a 2D sketch

jarle_oudalstoelEN4BR
Enthusiast Enthusiast
129 Views
1 Reply
Message 1 of 2

Trying to project 3Dsketch lines on to a 2D sketch

jarle_oudalstoelEN4BR
Enthusiast
Enthusiast

Hi All

 

I am trying to project singular 3Dsketches on to a 2D sketch. 

 

I am creating the sketch through iLogic and I was trying to use the 

AddByProjectingEntity 

function but i could not get that to work. 

 

here is the code I currently have. 

 

' Get the current document and its component definition
Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition

Dim NODE_COUNT As Integer = GoExcel.CellValue(EXCEL, Excel_Sheet_Name, Node_Count_Excel_Cell)
Dim ROW_COUNT As Integer = 0
Dim oNode As String

	ROW_NUMBER = 5

	Do Until ROW_COUNT = NODE_COUNT
	oNode = GoExcel.CellValue(EXCEL, Excel_Sheet_Name, "C" & ROW_NUMBER)

	Dim oWorkPlane As WorkPlane = oCompDef.WorkPlanes.Item(oNode & ": XY Plane")
	
	' Add a new sketch to the selected work plane
	Dim oSketch As PlanarSketch
	
	Try
		oSketch = oCompDef.Sketches.Item(oNode & " Sketch")
		oSketch.Delete
	Catch
	End Try
	
		oSketch = oCompDef.Sketches.Add(oWorkPlane)
	
	' Optionally, you can give the new sketch a name
		oSketch.Name = oNode & " Sketch"
		
'		oSketch.Edit
'		oSketch.AddByProjectingEntity("NR1_01 UCS_WP")
'		oSketch.ExitEdit
		
		ROW_COUNT = ROW_COUNT + 1
		ROW_NUMBER = ROW_NUMBER + 1

Loop

 

As you can see I've commented out the AddByProjectingEntity as It would not let me do that. 

the name in the parentheses is the name of a workplane that does intersect with this sketch plane. 

 

If someone has a good solution or tips for how I can solve this I'd appreciate that a lot. 

 

 

The  

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

J_Pfeifer_
Advocate
Advocate

First thing I'll point out, within the part document you do not need to enter (edit) the sketch object in order to interact with it. In fact, in my experience doing so would force rebuilds that created updates driving down run time. 

 

Now when it comes to projecting items I always take things step by step. Given I have no reference to what your trying to project "NR1_01 UCS_WP" it makes it hard to determine what's happening. I typically project other sketch items with variables directly. I do not reference them by name (string) this way. However, when I've run into issues projecting it comes from two main areas. Either The work plane or sketch I'm projecting to is not correct or projectable. This would look like projecting a line to a point on a perpendicular sketch. 

 

The other thing that would prevent or cause issues when projecting is the type. which you're not declaring and assigning. Basically the example given before. Projecting a line expecting a line, assigning it to a line object, only to learn that due to the orientation that projection is actually a point. So in this example you're assigning an incorrect variable type causing the failure. <--- This is not your problem as you're not assigning the creation to a variable. 

 

From here I would suggest to start logging and turning the visibility on the objects you're accessing. Force it to run and place "Exit sub" right before you have issues and investigate the CAD geometry and objects manually. Play around with visibilities, even attempt to create other objects not in your code currently. This may sound dumb, but playing around has gotten me through many of the isssues I had in creating features. 

 

What happens when you attempt to project this object manually setting up the planes you'd normally have programmed?

 

 

0 Likes