Ground Constraint

Ground Constraint

Anonymous
Not applicable
928 Views
9 Replies
Message 1 of 10

Ground Constraint

Anonymous
Not applicable

I get an error when creating a ground constraint in a sketch block. I don't know what the problem is.

Here is the code:

 

Dim oBlockDef As SketchBlockDefinition
Dim oPointCenter As SketchEntity
oObject = ThisApplication.ActiveEditObject

If oObject.Type = ObjectTypeEnum.kSketchBlockDefinitionObject Then
oBlockDef = ThisApplication.ActiveEditObject
opoint=ThisApplication.TransientGeometry.CreatePoint2d(0,0)
oPointCenter=oBlockDef.SketchPoints.add(opoint,True)
' Here is the errror
oBlockDef.GeometricConstraints.AddGround(opointCenter)
End If

 

0 Likes
929 Views
9 Replies
Replies (9)
Message 2 of 10

WCrihfield
Mentor
Mentor

Try it this way.

Dim oObject As Object = ThisApplication.ActiveEditObject

If TypeOf oObject Is SketchBlockDefinition Then 
      Dim oBlockDef As SketchBlockDefinition = ThisApplication.ActiveEditObject
      Dim oPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(0,0) 
      Dim oPointCenter As SketchPoint = oBlockDef.SketchPoints.Add(oPoint,True)
      ' Here is the errror
      oBlockDef.GeometricConstraints.AddGround(oPointCenter)
End If

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 10

Anonymous
Not applicable

Nope i still get the error.

Hhere is the situation and error:

Clipboard02.jpg

0 Likes
Message 4 of 10

J-Camper
Advisor
Advisor

This is weird behavior, I tried it in a regular sketch and it works perfect:

Sub Main
If ThisApplication.ActiveDocumentType <> kPartDocumentObject Then MessageBox.Show("This rule only works in Part files.", "Wrong Document type") : Exit Sub
Dim oBlock As Sketch = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchObjectFilter, "Select a Sketch") : If IsNothing(oBlock) Then Exit Sub
'Enter Block Editor
oBlock.Edit
Dim oPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)
Dim oPointCenter As SketchPoint
oPoint = ThisApplication.TransientGeometry.CreatePoint2d(0, 0) 
oPointCenter = oBlock.SketchPoints.Add(oPoint, True)
Try
	oBlock.GeometricConstraints.AddGround(oPointCenter)
Catch
	MessageBox.Show("Failed to make constraint.", "Error") : oPointCenter.Delete
End Try
oBlock.ExitEdit
End Sub

But then defining oBlock as a SketchBlockDefinition, it won't work:

Sub Main
If ThisApplication.ActiveDocumentType <> kPartDocumentObject Then MessageBox.Show("This rule only works in Part files.", "Wrong Document type") : Exit Sub
Dim oBlock As SketchBlockDefinition = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchBlockDefinitionFilter, "Select a Sketch Block") : If IsNothing(oBlock) Then Exit Sub
'Enter Block Editor
oBlock.Edit
Dim oPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)
Dim oPointCenter As SketchPoint
oPoint = ThisApplication.TransientGeometry.CreatePoint2d(0, 0) 
oPointCenter = oBlock.SketchPoints.Add(oPoint, True)
Try
	oBlock.GeometricConstraints.AddGround(oPointCenter)
Catch
	MessageBox.Show("Failed to make constraint.", "Error") : oPointCenter.Delete
End Try
oBlock.ExitEdit
End Sub

Seems like this might be a bug?  It should work in the SketchBlockDefinition context based on the documentation found in the help file

 

I did find a possible work around by creating your geometry in a sketch and use the CopyContentsTo method into a new block:

Sub Main
If ThisApplication.ActiveDocumentType <> kPartDocumentObject Then MessageBox.Show("This rule only works in Part files.", "Wrong Document type") : Exit Sub
Dim oBlock As Sketch = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchObjectFilter, "Select a Sketch") : If IsNothing(oBlock) Then Exit Sub
'Enter Block Editor
oBlock.Edit
Dim oPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)
Dim oPointCenter As SketchPoint
oPoint = ThisApplication.TransientGeometry.CreatePoint2d(0, 0) 
oPointCenter = oBlock.SketchPoints.Add(oPoint, True)
Try
	oBlock.GeometricConstraints.AddGround(oPointCenter)
Catch
	MessageBox.Show("Failed to make constraint.", "Error") : oPointCenter.Delete
End Try
oBlock.ExitEdit
Dim newBlock As SketchBlockDefinition
oBlock.CopyContentsTo(ThisApplication.ActiveDocument.ComponentDefinition.SketchBlockDefinitions.Add("new_Block"))End Sub
0 Likes
Message 5 of 10

Anonymous
Not applicable

Yeah i think it is also a bug 

0 Likes
Message 6 of 10

Anonymous
Not applicable

It seems i can't add any constraints via ilogic when in sketchblockdefinition. Is this a bug?

0 Likes
Message 7 of 10

HideoYamada
Advisor
Advisor

Hi,

 

I got a similar issue today and found this thread.

Has someone solved or found workaround?

 

I use .net API and c#.

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 8 of 10

J-Camper
Advisor
Advisor

@HideoYamada 

In the case of creating new sketch blocks, I posted a workaround where you build you geometry and constraints in a sketch and then CopyContentsTo a new sketch block. 

In the case of modifying existing sketch blocks or creating them directly as sketch blocks, I have not found anything.

0 Likes
Message 9 of 10

HideoYamada
Advisor
Advisor

Hello @J-Camper 

 

Thank you for replaying.

 


In the case of modifying existing sketch blocks or creating them directly as sketch blocks, I have not found anything.

I'm waiting for Autodesk to fix this issue.  ( ; _ ; )

 

=====

Freeradical

 Hideo Yamada

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 10 of 10

l.orzechowski
Explorer
Explorer

I'm struggling with same thing. Any news from Autodesk regarding that?

0 Likes