?
Solved

Lisp or VBA to change point coordinates

Posted on 2011-03-16
9
Medium Priority
?
1,547 Views
Last Modified: 2013-11-15
I'd like to run a Lisp or VBA routine that prompts a user to select a point and the code would apply a scale factor to the x,y coordinates of the point, then draw another point with the new (scaled) x,y values.
This is within Autocad 10 or earlier.

Thanks
0
Comment
Question by:LDP-bb
7 Comments
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 35186455
So if you select point 3,5 and a scale factor of 3 then draw a point at 9,15. Is that right?

Saqib
0
 

Author Comment

by:LDP-bb
ID: 35190903
Saqib:

Yes, say an existing point has x,y, z coordinates of 3,5,0, you would run the custom command code from an custom icon added to the Autocad Menu that would prompt you to choose an existing point , then the code would prompt you for the base point in the drawing to apply the scale factor from (or apply a standard base point , see below), then the code would appliy a set scale factor to that point embedded in the code (that factor could be edited in the code later depending on the project) and then draw another point at the scaled coordinate points. For instance In your example, another point at  9,15,0.  I hope to build two commnad icons eventually, one with a scale factor of .999896 and another at 1.000104. (Note the base point may also be set as as constant but would vary with different projects, however within a single project, that base point would remain a constant , the coordinator would change the code of the basepoint for each project). This is to facilitate the conversion of points from Grid to Ground (and vice versa) in surveyed site plans. Across a single project the base point and conversion factors would remain the same. To apply the commonad to different projects the code would simply need revision of those variables but remain useful. .  

Thanks
LDP

0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 1500 total points
ID: 35193594
Try this code. You will have to give a filename with path on the second line where the program will maiintain a parameter file.

Saqib
Sub scpoint()
floc = "C:\Documents and Settings\Saqib\My Documents\scale.txt"
On Error Resume Next
Open floc For Input As #1
If Err Then
    Err.Clear
    sc = 1
    xb = 0
    yb = 0
    zb = 0
    ip(0) = "scale=" & sc
    ip(1) = "x=" & xb
    ip(2) = "y=" & yb
    ip(3) = "z=" & zb
    Open floc For Output As #1
    Print #1, Join(ip, vbCrLf)
Else
    ip = Input(LOF(1), 1)
    Close 1
    ip = Split(ip, vbCrLf)
    sc = Val(Right(ip(0), Len(ip(0)) - 6))
    xb = Val(Right(ip(1), Len(ip(1)) - 2))
    yb = Val(Right(ip(2), Len(ip(2)) - 2))
    zb = Val(Right(ip(3), Len(ip(3)) - 2))
End If
    On Error Resume Next
    keywordList = "s scale b basepoint"
    ThisDrawing.Utility.InitializeUserInput 128, keywordList
    ds = "Scale = " & sc & vbCr & xb & "," & yb & "," & zb & vbCr
    returnPnt = ThisDrawing.Utility.GetPoint(, ds & "Enter a point or (Scale, Basepoint): ")
    If Err Then
         If StrComp(Err.Description, "User input is a keyword", 1) = 0 Then
             Err.Clear
             inputString = ThisDrawing.Utility.GetInput
             Select Case inputString
                Case "s"
                    sc = InputBox("Enter new scale (" & sc & "): ", "Redefine parameter", sc)
                    ip(0) = "scale=" & sc
                    Open floc For Output As #1
                    Print #1, Join(ip, vbCrLf)
                    Close 1
                    Call scpoint
                Case "b"
                    returnPnt = ThisDrawing.Utility.GetPoint(, "Enter base point: ")
                    ip(1) = "x=" & returnPnt(0): xb = ip(1)
                    ip(2) = "y=" & returnPnt(1): yb = ip(2)
                    ip(3) = "z=" & returnPnt(2): zb = ip(3)
                    Open floc For Output As #1
                    Print #1, Join(ip, vbCrLf)
                    Close 1
                    Call scpoint
                Case Else
                End
             End Select
         End If
    Else
    np = returnPnt
    np(0) = (returnpoint(0) - xb) * sc
    np(1) = (returnpoint(1) - yb) * sc
    np(2) = (returnpoint(2) - zb) * sc
    ThisDrawing.ModelSpace.AddPoint (np)
    End If
End Sub

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:Tommy Kinard
ID: 35207617
@ssaqibh

This will need to be in lisp I think because vba was not in version 10.

Just a heads up. :)

dragontooth
0
 
LVL 12

Expert Comment

by:silverkorn
ID: 35207694
you are correct that VBA is not included with AutoCAD 2010, or 2011 for that matter, but you can add it by using this download:
http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=12715668&linkID=9240618

as of now it is unsure if 2012 products will have this VBA add on and Autodesk is suggesting that any new programs be written in the VB.NET programming language.
0
 

Author Closing Comment

by:LDP-bb
ID: 35207833
My knowledge of VBA is limited and the application of VBA within recent versions of Autocad is limited as well. I did not know the latter fact. I wil persue the lisp and/or VB.net transaltion of the code.  I have other CAD programming sites this topic. This posting can be closed .
Thanks Everyone.

Regards
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 35208231
I am sorry but you should reopen the question. I shall try to workout a routine in lisp. Awarding a grade of 'B' is not right.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question