Solved

Lisp or VBA to change point coordinates

Posted on 2011-03-16
9
1,505 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
9 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 500 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

860 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