### [Solved] VBA Transformby method does not work

progeCAD support, tips and troubleshooting forum. progeCAD works very similar to some versions of AutoCAD. Moderated.

Moderators: caddit, Moderators

### [Solved] VBA Transformby method does not work

#2343 by jouni
Fri Oct 28, 2016 9:03 am
Hello

This is a example code which is not working. Progecad 2014.
How should I fill the Matrix? Couldn't find a solution.

Sub TransformBy()
' This example creates a line and rotates it 90 degrees
' using a transformation matrix.
Dim myDoc As IntelliCAD.Document
' Create a line
Dim lineObj As IntelliCAD.Line
Dim startPt As IntelliCAD.Point
Dim endPt As IntelliCAD.Point
Set myDoc = Application.ActiveDocument
Set startPt = Library.CreatePoint(2, 1, 0)
'startPt(0) = 2: startPt(1) = 1: startPt(2) = 0
'endPt(0) = 5: endPt(1) = 1: endPt(2) = 0
Set endPt = Library.CreatePoint(5, 1, 0)
Set lineObj = myDoc.ModelSpace.AddLine(startPt, endPt)
lineObj.Update

' Initialize the transMat variable with a transformation matrix
' that will rotate an object by 90 degrees about the point(0,0,0)
' (More examples of transformation matrices are listed below)
'Dim transArray(0 To 3, 0 To 3) As Double
Dim transMat(0 To 3, 0 To 3) As Matrix

transMat(0, 0) = 0: transMat(0, 1) = -1: transMat(0, 2) = 0: transMat(0, 3) = 0
transMat(1, 0) = 1: transMat(1, 1) = 0: transMat(1, 2) = 0: transMat(1, 3) = 0
transMat(2, 0) = 0: transMat(2, 1) = 0: transMat(2, 2) = 1: transMat(2, 3) = 0
transMat(3, 0) = 0: transMat(3, 1) = 0: transMat(3, 2) = 0: transMat(3, 3) = 1

'transArray(0, 0) = 0: transArray(0, 1) = -1: transArray(0, 2) = 0: transArray(0, 3) = 0
'transArray(1, 0) = 1: transArray(1, 1) = 0: transArray(1, 2) = 0: transArray(1, 3) = 0
'transArray(2, 0) = 0: transArray(2, 1) = 0: transArray(2, 2) = 1: transArray(2, 3) = 0
'transArray(3, 0) = 0: transArray(3, 1) = 0: transArray(3, 2) = 0: transArray(3, 3) = 1

' Transform the line using the defined transformation matrix
MsgBox "Transform the line.", , "TransformBy Example"
lineObj.TransformBy (transMat) ' creates Type mismatch error

'ZoomAll
MsgBox "The line is transformed.", , "TransformBy Example"
End Sub
Last edited by jouni on Tue Nov 15, 2016 2:23 pm, edited 2 times in total.

### Re: VBA Tranformby method does not work

#2344 by caddit
Thu Nov 03, 2016 4:07 am
Hello jouni,

progeCAD changed the data type which defines the 3D transformation matrix some time ago.
The new data type, called "Matrix", includes all of the 3D matrix data in a single VBA object.
Your VBA procedure should therefore be rewritten as below. Please test it and let us know:

Code: Select all`    Sub TransformBy()        ' This example creates a line and rotates it 90 degrees        ' using a transformation matrix.        Dim myDoc As IntelliCAD.Document        ' Create a line        Dim lineObj As IntelliCAD.Line        Dim startPt As IntelliCAD.Point        Dim endPt As IntelliCAD.Point        Set myDoc = Application.ActiveDocument        Set startPt = Library.CreatePoint(2, 1, 0)        Set endPt = Library.CreatePoint(5, 1, 0)        Set lineObj = myDoc.ModelSpace.AddLine(startPt, endPt)        lineObj.Update        ' Initialize the transMat variable with a transformation matrix        ' that will rotate an object by 90 degrees about the point(0,0,0)        ' (More examples of transformation matrices are listed below)        Dim transMat As New IntelliCAD.Matrix        Call transMat.SetValue(0, 0, 0)        Call transMat.SetValue(1, 0, 1)        Call transMat.SetValue(2, 0, 0)        Call transMat.SetValue(3, 0, 0)        Call transMat.SetValue(0, 1, -1)        Call transMat.SetValue(1, 1, 0)        Call transMat.SetValue(2, 1, 0)        Call transMat.SetValue(3, 1, 0)        Call transMat.SetValue(0, 2, 0)        Call transMat.SetValue(1, 2, 0)        Call transMat.SetValue(2, 2, 1)        Call transMat.SetValue(3, 2, 0)        Call transMat.SetValue(0, 3, 0)        Call transMat.SetValue(1, 3, 0)        Call transMat.SetValue(2, 3, 0)        Call transMat.SetValue(3, 3, 1)        ' Transform the line using the defined transformation matrix        MsgBox "Transform the line.", , "TransformBy Example"        Call lineObj.TransformBy(transMat) ' creates Type mismatch error        'ZoomAll        MsgBox "The line is transformed.", , "TransformBy Example"    End Sub`

### Re: VBA Tranformby method does not work

#2345 by jouni
Thu Nov 03, 2016 3:30 pm
Hello
Your code works fine. The way of setting values to the matrix is also new for me.

Many thanks!

### Re: [Solved] VBA Tranformby method does not work

#2346 by jouni
Mon Nov 07, 2016 10:44 am
For studying transformby method I changed the code. Now it will transform the selection set instead of a single line. Have fun with this.

Sub Transform()
' This example rotates the selectionset 90 degrees
' using a transformation matrix.
Dim myDoc As IntelliCAD.Document
Dim selSet As IntelliCAD.SelectionSet
Set myDoc = Application.ActiveDocument

' Initialize the transMat variable with a transformation matrix
' that will rotate an object by 90 degrees about the point(0,0,0)

Dim transMat As New IntelliCAD.Matrix

Call transMat.SetValue(0, 0, 0)
Call transMat.SetValue(1, 0, 1)
Call transMat.SetValue(2, 0, 0)
Call transMat.SetValue(3, 0, 0)

Call transMat.SetValue(0, 1, -1)
Call transMat.SetValue(1, 1, 0)
Call transMat.SetValue(2, 1, 0)
Call transMat.SetValue(3, 1, 0)

Call transMat.SetValue(0, 2, 0)
Call transMat.SetValue(1, 2, 0)
Call transMat.SetValue(2, 2, 1)
Call transMat.SetValue(3, 2, 0)

Call transMat.SetValue(0, 3, 0)
Call transMat.SetValue(1, 3, 0)
Call transMat.SetValue(2, 3, 0)
Call transMat.SetValue(3, 3, 1)

On Error Resume Next
Set selSet = myDoc.SelectionSets.Add("Objects")
If Err.Number <> 0 Then

myDoc.SelectionSets.Item("Objects").Delete
Set selSet = myDoc.SelectionSets.Item("Objects")
selSet.Clear
End If

selSet.Clear
selSet.SelectOnScreen
selSet.Highlight True
' Transform the selectionset using the defined transformation matrix
MsgBox "Transform the objects.", , "TransformBy Example"

Call selSet.TransformBy(transMat)

myDoc.Regen
MsgBox "Objects are transformed.", , "TransformBy Example"
selSet.Highlight False
selSet.Clear
selSet.Delete

End Sub

### Recent Topics

copybase

by fging

Thu Jul 01, 2021 9:33 pm

ProgeCAD 2017 won't load

by caddit

Wed Apr 21, 2021 3:15 am

Command Bar max character input length

by caddit

Wed Mar 10, 2021 12:13 pm

Narrow Lines

by peefjay

Mon Nov 23, 2020 4:36 am

### About Us

Welcome to Ausstralia/New Zealand's CADDIT CAD software forum. CAD CAM Forum for support and discussion regarding AutoCAD, progeCAD IntelliCAD, Geomagic Freeform, Mathcad, CNC software.

This forum offers free support for progeCAD by qualified technical staff. Thank you for visiting.

CADDIT.net

The CADDIT.net team