Solved

Lisp or VBA to change point coordinates

Posted on 2011-03-16
9
1,498 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

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.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

777 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