Solved

Lisp or VBA to change point coordinates

Posted on 2011-03-16
9
1,520 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Webinar: MariaDB® Server 10.2: The Complete Guide

Join Percona’s Chief Evangelist, Colin Charles as he presents MariaDB Server 10.2: The Complete Guide on Tuesday, June 27, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
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 …
Starting up a Project

695 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