Rabu, 16 Februari 2011

Knowledge detail

Migrating VBA

Q: Is it possible to migrate my VBA applications from AutoCAD to ZWCAD?
A: Yes, of course! VBA is designed to be portable between applications. But you will need to make some modifications before migrating the code, which can be done with global search and replace. The changes are as follows:

1. Replace “thisdocument” with “thisdrawing”.
2. All the object names with the prefix of “acad” must be changed to “zwcad”. For example, change “acadLine” to “zwcadLine” and change “acadArc” to “zwcadArc”.
3. The head of the enumeration must be changed from “Ac” to “zc”. For example, change the enumeration about HATCH as follows:
• Change “AcHatchStyle” to “zcHatchStyle”
• Change “AcHatchStyleIgnore” to “zcHatchStyleIgnore”
• Change “AcHatchStyleNormal” to “zcHatchStyleNormal”
• Change “AcHatchStyleOuter” to “zcHatchStyleOut”
Note that there are two special enumerations:
• Change “ACAD_COLOR” to “ZcCOLOR”
• Change “ACAD_LWEIGHT” to “ZCLINEWEIGHT”
4.There is no “Objectname” or “Objecttype” property in this version of ZWCAD. Instead, use “Entityname” and “Entitytype”. If the object is an entity, you can replace them; otherwise, use the “name” property.
Note that it is best to use “Entitytype” if the object has this property, because the name of the object may change in future releases.
5. AutoCAD uses arrays to store points, but ZWCAD defines points as objects, as shown in the following sample code:
Dim PointObj as new Zwcadpoint ‘Must use the NEW function
‘The same mode in AutoCAD and ZWCAD
PointObj(0) = 1
PointObj(1) = 1
PointObj(2) = 1
‘Another mode in ZWCAD
PointObj.x=1
PointObj.x=1
PointObj.x=1
If you want to get a point from user, you must use the SET function, because point is an object. Here is a sample piece of code:
Set PointObj = ThisDocument.Utility.GetPoint(, vbCrLf & “Please choose a point: ”)
When you need to deal with many points, AutoCAD uses array, but ZWCAD uses the “zwcadpoints” class, as illustrated by this sample code:
Dim points as new zwcadpoints ‘Must use NEW to built a list
Dim point as new zwcadpoint
Set point = points.add(x, y, z, item)
5. AutoCAD’s 3dvector is defined as an array, but in ZWCAD it is named “zwcadVector”. It is an object in ZWCAD, so you must to create it with the NEW and SET functions. Here is an example:
‘Define points and vector
Dim Spline as zwcadspline
Dim Points as zwcadpoints
Dim pointObj as new zwcadpoint
Dim startVector as new zwcadVector
Dim endVector as new ZwcadVector
‘Set points
Set PointObj = Points.Add(0, 0, 0, 0) 
Set PointObj = Points.Add(1, 5, 0, 1)
Set PointObj = Points.Add(9, 10, 0, 2)
‘Set vector
startVector.x = 0.5
startVector.y = 0.5
startVector.z = 0
endVector.x = 0.5
endVector.y = 0.5
endVector.z = 0
‘Drawing a SPLINE
Set splineObj = ThisDocument.ModelSpace.AddSpline(Points, startVector, endVector)

Tidak ada komentar:

Posting Komentar