VBA PROBLEM

VBA PROBLEM

tsimaros
Contributor Contributor
2,414 Views
4 Replies
Message 1 of 5

VBA PROBLEM

tsimaros
Contributor
Contributor

 am trying to translate a Point coordinates from Paperspce to world coordinates in model space.The code i used in Land2006 worked OK but now in Civil3d 2012 it doesn't!

 

Private Sub GetPlais_Click()
Dim tmpnt1 As Variant, tmpnt2 As Variant, tmpPnt1 As Variant
Dim lole(0 To 2) As Double, upri(0 To 2) As Double
Dim returnobj As AcadObject

FrmGrid3.Hide
On Error GoTo Eline
ThisDrawing.Utility.GetEntity returnobj, tmpPnt1, "ÅðÝëåîå ôï ViewPort ðïõ èá äçìéïõñãçèåß ï êÜíáâïò!"
If TypeOf returnobj Is IAcadPViewport Then
Set viewportObj = returnobj
viewportObj.UCSIconOn = True
viewportObj.UCSIconAtOrigin = True
viewportObj.Display True
Scal = 1000 / viewportObj.CustomScale '= 1000 / CDbl(cbScale.Text)

Else
MsgBox "ÄÝí åðÝëåîåò ViewPort!!!", vbOKOnly, "Ó÷åäßáóç êáíÜâïõ"
FrmGrid3.Show
Exit Sub
End If
lole(0) = viewportObj.Center(0) - viewportObj.Width / 2
lole(1) = viewportObj.Center(1) - viewportObj.Height / 2
upri(0) = viewportObj.Center(0) + viewportObj.Width / 2
upri(1) = viewportObj.Center(1) + viewportObj.Height / 2

PntUpLPap(0) = lole(0): PntDoLPap(0) = lole(0): PntUpRPap(0) = upri(0): PntDoRPap(0) = upri(0)
PntUpLPap(1) = upri(1): PntDoLPap(1) = lole(1): PntUpRPap(1) = upri(1): PntDoRPap(1) = lole(1)

tmpnt1 = ThisDrawing.Utility.TranslateCoordinates(lole, acPaperSpaceDCS, acDisplayDCS, False)
tmpnt1 = ThisDrawing.Utility.TranslateCoordinates(tmpnt1, acDisplayDCS, acWorld, False)
TxtDoLX.Text = Format(tmpnt1(0), "0.##0"): PntDoLmod(0) = tmpnt1(0)
TxtDoLY.Text = Format(tmpnt1(1), "0.##0"): PntDoLmod(1) = tmpnt1(1)

tmpnt1 = ThisDrawing.Utility.TranslateCoordinates(upri, acPaperSpaceDCS, acDisplayDCS, False)
tmpnt1 = ThisDrawing.Utility.TranslateCoordinates(tmpnt1, acDisplayDCS, acWorld, False)
TxtUpRX.Text = Format(tmpnt1(0), "0.##0"): PntUpRmod(0) = tmpnt1(0)
TxtUpRY.Text = Format(tmpnt1(1), "0.##0"): PntUpRmod(1) = tmpnt1(1)

tmpnt1(0) = lole(0)
tmpnt1(1) = upri(1)
tmpnt1 = ThisDrawing.Utility.TranslateCoordinates(tmpnt1, acPaperSpaceDCS, acDisplayDCS, False)
tmpnt1 = ThisDrawing.Utility.TranslateCoordinates(tmpnt1, acDisplayDCS, acWorld, False)
TxtUpLX.Text = Format(tmpnt1(0), "0.##0"): PntUpLmod(0) = tmpnt1(0)
TxtUpLY.Text = Format(tmpnt1(1), "0.##0"): PntUpLmod(1) = tmpnt1(1)

tmpnt1(0) = upri(0)
tmpnt1(1) = lole(1)
tmpnt1 = ThisDrawing.Utility.TranslateCoordinates(tmpnt1, acPaperSpaceDCS, acDisplayDCS, False)
tmpnt1 = ThisDrawing.Utility.TranslateCoordinates(tmpnt1, acDisplayDCS, acWorld, False)
TxtDoRX.Text = Format(tmpnt1(0), "0.##0"): PntDoRmod(1) = tmpnt1(0)
TxtDoRY.Text = Format(tmpnt1(1), "0.##0"): PntDoRmod(1) = tmpnt1(1)

Eline:
FrmGrid3.Show
End Sub

I can't understand the problem!!!!

0 Likes
2,415 Views
4 Replies
Replies (4)
Message 2 of 5

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> The code i used in Land2006 worked OK but now in Civil3d 2012 it doesn't!

What does the code not do?

We don't have your form, so we can just read (& interpret) your lines and guess what your form FRMGRID3 contains, but we can not try your code. And if you don't give us the info "at what line" happens "what error" you can't expect that anyone reacts to this thread (with that title 😉 ).

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 5

tsimaros
Contributor
Contributor

IThanks for the reply.

I dont have an error code!It just gives me false results!!!!

The code refers to a command button that prompts you to select a Viewport object (returnobj) from which i get the lowerleft and upper right  paperspace coords. I store that coords for later and want to get the same coords but in Model space:

tmpnt1 = ThisDrawing.Utility.TranslateCoordinates(lole, acPaperSpaceDCS, acDisplayDCS, False)
'tmpnt1 = ThisDrawing.Utility.TranslateCoordinates(tmpnt1, acDisplayDCS, acWorld, False)!

This works fine in LAND2006 but not in Civil 3D?????

0 Likes
Message 4 of 5

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

prepare a drawing with one layout containing one viewport.

Upload it and let us knw what coordinates you get. Then we can start 😉

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 5 of 5

Ed__Jobe
Mentor
Mentor

You can also embed the vba.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes