Run-time error '13' Type mismatch

Run-time error '13' Type mismatch

austen_27_t
Contributor Contributor
1,354 Views
2 Replies
Message 1 of 3

Run-time error '13' Type mismatch

austen_27_t
Contributor
Contributor

Can anyone find where this mismatch error is occurring I have been trying to fix it but have not been successful.

Ive attached a picture of the code also showing the error.

 

Thank you to anyone who can help

 

 

Public Sub hex()

'activate the part as a document

Dim pdoc As PartDocument
Set pdoc = ThisApplication.ActiveDocument

Dim pdef As PartComponentDefinition
Set pdef = pdoc.ComponentDefinition

'Establish input dimensions
Dim dim1, dim2
dim1 = InputBox("Enter Hex Size", "HEX")
dim2 = InputBox("Enter Hex Length", "Length")

Dim sides As Long
sides = 6

 

'create new reference sketch plane
Dim sketch As PlanarSketch
Set sketch = pdef.Sketches.Add(pdef.WorkPlanes.Item(3))

'Sets reference to tg transient geometry
Dim tg As TransientGeometry
Set tg = ThisApplication.TransientGeometry


'Create lines for polygon
Dim hex As SketchLine
Set hex = sketch.SketchLines.AddAsPolygon(sides, tg.CreatePoint2d(0, 0), tg.CreatePoint2d(0, dim1), False)

 

'Creates a profile.
Dim Pfile As Profile
Set Pfile = sketch.Profiles.AddForSolid

'Create an extrusion.
Dim extrudeDef As ExtrudeDefinition
Set extrudeDef = pdoc.Features.ExtrudeFeatures.CreateExtrudeDefinition(Pfile, kJoinOperation)

Call extrudeDef.SetDistanceExtent(dim2, kNegativeExtentDirection)
Dim extrude As ExtrudeFeature
Set extrude = pdoc.Features.ExtrudeFeatures.Add(extrudeDef)

End Sub

0 Likes
1,355 Views
2 Replies
Replies (2)
Message 2 of 3

tdant
Collaborator
Collaborator

I think your problem is dim1. The original variable is set as a String, and the CreatePoint2D method takes Doubles as its arguments. Depending on what you're putting in the InputBox for dim1, a possible solution would be to wrap the InputBox in a CDbl(). Does that make sense?

0 Likes
Message 3 of 3

leowarren34
Mentor
Mentor

What inventor build is this, and what OS are you using?

Leo Warren
Autodesk Student Ambassador Diamond
Please accept as solution and give likes if applicable.
0 Likes