Solved

Lisp or VBA to change point coordinates

Posted on 2011-03-16
9
1,486 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 14

Expert Comment

by:Tommy Kinard
Comment Utility
@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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now