Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

AddExtrudedSolidAlongPath Automation Control from VB

Status
Not open for further replies.

CTruax

Civil/Environmental
May 21, 2001
82
I get a type mismatch error with the following code:
Dim noOfPoints As Integer: noOfPoints = 5
ReDim P(0 To noOfPoints * 2 - 1) As Double
P(0) = 0#: P(1) = 0#
P(2) = L: P(3) = 0#
P(4) = L: P(5) = Th
P(6) = 0#: P(7) = Th
P(8) = 0#: P(9) = 0# 'a closed polyline
Dim ObjectList(0 To 0) As Object 'in this case an array length of 1
Set ObjectList(0) = acadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(P)

Dim Regions As Variant
Regions = acadApp.ActiveDocument.ModelSpace.AddRegion(ObjectList)

Dim PointsArray(0 To 5) As Double
PointsArray(0) = 0: PointsArray(1) = 0: PointsArray(2) = 0
PointsArray(3) = 0: PointsArray(4) = 0: PointsArray(5) = 6
Dim anObj As Object
Set anObj = acadApp.ActiveDocument.ModelSpace.AddExtrudedSolidAlongPath(Regions, PointsArray)

I can perform the task from the ACAD R14 command line but why do I get a MisMatch error on the last statement?
 
Replies continue below

Recommended for you

RetVal = ThisDrawing.ModelSpace.AddExtrudedSolidAlongPath(Regions, tempPolyLine)

Second argument has to be PolyLine, Circle, Ellipse, Spline or Arc.
Maybe if a tempPolyline is produced from the pointsarray, then it will work.
 
Hi again. The following works. Use Regions(0) as arguments. Hope this is useful.

Sub myExtrude()
'I get a type mismatch error with the following code:
'Solution: use Regions(0) as argument

Dim noOfPoints As Integer: noOfPoints = 5
ReDim P(0 To noOfPoints * 2 - 1) As Double
L = 10: Th = 10
P(0) = 0#: P(1) = 0#
P(2) = L: P(3) = 0#
P(4) = L: P(5) = Th
P(6) = 0#: P(7) = Th
P(8) = 0#: P(9) = 0# 'a closed polyline
Dim ObjectList(0 To 0) As Object 'in this case an array length of 1
'Set ObjectList(0) = AcadApplication.ActiveDocument.ModelSpace.AddLightWeightPolyline(P)
Set ObjectList(0) = ThisDrawing.ModelSpace.AddLightWeightPolyline(P)
Dim Regions As Variant
Regions = ThisDrawing.ModelSpace.AddRegion(ObjectList)
Regions(0).Color = acRed

Dim PointsArray(0 To 5) As Double
PointsArray(0) = 0: PointsArray(1) = 0: PointsArray(2) = 0
PointsArray(3) = 0: PointsArray(4) = 0: PointsArray(5) = 500
Dim anObj As Object
'Set anObj = AcadApp.ActiveDocument.ModelSpace.AddExtrudedSolidAlongPath(Regions, PointsArray)
Dim tempPolyline As Acad3DPolyline
Set tempPolyline = ThisDrawing.ModelSpace.Add3DPoly(PointsArray)
Set anObj = ThisDrawing.ModelSpace.AddExtrudedSolidAlongPath(Regions(0), tempPolyline)
ThisDrawing.ActiveViewport.ZoomAll
End Sub
 
OK Thanks. I wish I would have posted several days ago and avoided online documentation grief.

Dim tempPolyline As Acad3DPolyline 'your code
Dim tempPolyline As Object 'my code
How do you get away with this?
I'm using VB6 and Acad R16. I loaded the Acad.tlb and it shows as a reference.
 
I felt the uncontrollable need to clean up the code a bit.

Sub myExtrude()
'declarations
'note LWPolyObj only has 4 points on a 4 sided object
Dim noOfPoints As Integer: noOfPoints = 4
Dim regionObj As Variant
Dim PointsArray(0 To 5) As Double
Dim SolidObj As Acad3DSolid
Dim tempPolyline As Acad3DPolyline
Dim LWPolyObj(0 To 0) As AcadEntity
ReDim P(0 To noOfPoints * 2 - 1) As Double

' initializations
l = 10: Th = 10

PointsArray(0) = 0: PointsArray(1) = 0: PointsArray(2) = 0
PointsArray(3) = 0: PointsArray(4) = 0: PointsArray(5) = 500

P(0) = 0#: P(1) = 0#
P(2) = l: P(3) = 0#
P(4) = l: P(5) = Th
P(6) = 0#: P(7) = Th

'create LWPolyObj for regionObj
Set LWPolyObj(0) = ThisDrawing.ModelSpace.AddLightWeightPolyline(P)

'Use the closed property of the LWPolyObj
LWPolyObj(0).Closed = True

'create regionObj using LWPolyObj list
regionObj = ThisDrawing.ModelSpace.AddRegion(LWPolyObj)

'create a path to follow
Set tempPolyline = ThisDrawing.ModelSpace.Add3DPoly(PointsArray)

'create solid object using regionObj and tempPolyline
Set SolidObj = ModelSpace.AddExtrudedSolidAlongPath(regionObj(0), tempPolyline)

'delete LWPolyObj
LWPolyObj(0).Delete
'delete regionObj
regionObj(0).Delete
'delete tempPolyLine
tempPolyline.Delete
'now zoom all
ZoomAll
End Sub

 
Both work.
Dim tempPolyline As Acad3DPolyline 'your code
Dim tempPolyline As Object 'my code

Object or entity - often even variant.
In VBA, when Object, no curser hint to methods and properties. When Acad3DPoly etc., upon typiong the dot, pop up menu shows relevant properties etc.
The trick was that addGroup returns an array - I would never have expected this.

Glad it was useful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor