AddDiameter Sketch Constraint help

AddDiameter Sketch Constraint help

mslosar
Advisor Advisor
444 Views
1 Reply
Message 1 of 2

AddDiameter Sketch Constraint help

mslosar
Advisor
Advisor

I've search for references to AddDiameter and there is very little. Tells me no one uses it or it should be pretty easy.

 

I've got he following:

 

Public Sub BP()
    ' Create a new part document, using the default part template.
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, _
                ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))
                    
    ' Set a reference to the component definition.
    Dim oCompDef As PartComponentDefinition
    Set oCompDef = oPartDoc.ComponentDefinition
    
    ' Create a new sketch on the X-Z work plane.  Since it's being created on
    Dim oSketch As PlanarSketch
    Set oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes(2))
    
    ' Set a reference to the transient geometry object.
    Dim oTransGeom As TransientGeometry
    Set oTransGeom = ThisApplication.TransientGeometry
    
    ' Draw a 4cm x 3cm rectangle with the corner at (0,0)
    Dim oc As SketchCircle
        
    Set oc = oSketch.SketchCircles.AddByCenterRadius(oTransGeom.CreatePoint2d(0, 0), 24 * 2.54)
    
    Dim DimC As DimensionConstraint
    DimC = oSketch.DimensionConstraints.AddDiameter(oc, oTransGeom.CreatePoint2d(3, 3), False)

end sub

Basically, it just creates a circle and then tries to dimension it.

 

The code actually places a diameter dimension on the sketch, but it errors every time saying Run time error '91' - object variable or With block variable not set.

 

I'm not seeing anything that tells me what the problem is, other than debug points to the DimC - osketch............ line where the constraint is created/placed.

 

If it can place the constraint, why is it creating an error presumably after the fact?

0 Likes
Accepted solutions (1)
445 Views
1 Reply
Reply (1)
Message 2 of 2

mslosar
Advisor
Advisor
Accepted solution

Grr...

 

freaking mixed environments....can't write for .net inside vba!!

 

Set DimC = ..........

 

 

0 Likes