Jump to content

Recommended Posts

Posted (edited)

Hello,

 

Im trying to produce a mapping programme within Autocad that allows a user to select an area from an image based map and load in digital mapping data.

 

The user should be able to select an area and load it into a frame of there size and at any selected scale.

 

Heres the coding i have so far, which should load the map, however it doesnt seem to be working as im getting a debug error with GetPoint. Could anyone help me with this as its driving me crazy!

 

Private Sub CommandButton1_Click()
Dim clickPoint As Variant
Dim dblclickPoint(0 To 2) As Double

Me.Hide

clickPoint = ThisDrawing.Utility.GetPoint(Prompt = "Select a point on map...")
dblclickPoint(0) = clickPoint(0)
dblclickPoint(1) = clickPoint(1)
dblclickPoint(2) = 0

'Create some varibles to insert map block / file
Dim mapBlock As AcadBlockReference
Dim blockInsert(0 To 2) As Double
blockInsert(0) = 0
blockInsert(1) = 0
blockInsert(2) = 0

If dblclickPoint(0) > 390000 And dblclickPoint(0) > 395000 And dblclickPoint(1) > 295000 And dblclickPoint(1) < 300000 Then
MsgBox ("You chosen the North West")
Set mapBlock = ThisDrawing.ModelSpace.InsertBlock(blockInsert, "T:/SO99NW.dwg", 1, 1, 1, 0)
End If

If dblclickPoint(0) > 390000 And dblclickPoint(0) > 395000 And dblclickPoint(1) > 290000 And dblclickPoint(1) < 295000 Then
MsgBox ("You chosen the South West")
Set mapBlock = ThisDrawing.ModelSpace.InsertBlock(blockInsert, "T:/SO99SW.dwg", 1, 1, 1, 0)
End If

Me.Show

End Sub

 

Cheers!

Edited by SLW210
Add tags
Posted

You need to use code tags (#) for your code. I have moved this to the .NET, ObjectARX and VBA forum.

Posted

Try changing:

 

clickPoint = ThisDrawing.Utility.GetPoint(Prompt = "Select a point on map...")

 

to:

 

clickPoint = ThisDrawing.Utility.GetPoint(, vbCr & "Select a point on map...")

Posted

when i click on a point it just opens the main form again.

Posted

Try changing the two red greater than symbols to less than symbols. If you don't you will never enter the if statements.

Private Sub CommandButton1_Click()
Dim clickPoint As Variant
Dim dblclickPoint(0 To 2) As Double

Me.Hide

clickPoint = ThisDrawing.Utility.GetPoint(Prompt = "Select a point on map...")
dblclickPoint(0) = clickPoint(0)
dblclickPoint(1) = clickPoint(1)
dblclickPoint(2) = 0

'Create some varibles to insert map block / file
Dim mapBlock As AcadBlockReference
Dim blockInsert(0 To 2) As Double
blockInsert(0) = 0
blockInsert(1) = 0
blockInsert(2) = 0

If dblclickPoint(0) > 390000 And dblclickPoint(0) [b][color=red]>[/color][/b] 395000 And dblclickPoint(1) > 295000 And dblclickPoint(1) < 300000 Then
MsgBox ("You chosen the North West")
Set mapBlock = ThisDrawing.ModelSpace.InsertBlock(blockInsert, "T:/SO99NW.dwg", 1, 1, 1, 0)
End If

If dblclickPoint(0) > 390000 And dblclickPoint(0) [b][color=red]>[/color][/b] 395000 And dblclickPoint(1) > 290000 And dblclickPoint(1) < 295000 Then
MsgBox ("You chosen the South West")
Set mapBlock = ThisDrawing.ModelSpace.InsertBlock(blockInsert, "T:/SO99SW.dwg", 1, 1, 1, 0)
End If

Me.Show

End Sub

 

And check the syntax of your block insertion!

Posted

nope still the same :(

 

Errors with this bit:

 

clickPoint = ThisDrawing.Utility.GetPoint(Prompt = "Select a point on map...")

Posted
nope still the same :(

 

Errors with this bit:

 

clickPoint = ThisDrawing.Utility.GetPoint(Prompt = "Select a point on map...")

 

See post 4 and change

clickPoint = ThisDrawing.Utility.GetPoint(Prompt = "Select a point on map...")
Posted

Nah mate it doesnt work. When i click on a point it just opens the form again.

Posted

I've tried your code with the changes to the > symbols and because I don't have a T: drive I created blocks in the drawing to simulate your DWGs and it all worked fine. Have a look at your insertion of your DWGs, the problem must be there. Good luck.

Posted

It didnt work. Could you show me how you have your coding?

Posted

I created a new project and inserted a module and a form.

 

The code for the module is:

 

Option Explicit

Sub Maps()
   UserForm1.Show
End Sub

The form (UserForm1) has one button (CommandButton1) and the code for the form is:

 


Option Explicit

Private Sub CommandButton1_Click()

   Dim clickPoint As Variant
   Dim dblclickPoint(0 To 2) As Double
    
   Me.Hide
    
   clickPoint = ThisDrawing.Utility.GetPoint(, "Select a point on map...")
   dblclickPoint(0) = clickPoint(0)
   dblclickPoint(1) = clickPoint(1)
   dblclickPoint(2) = 0
    
   'Create some varibles to insert map block / file
   Dim mapBlock As AcadBlockReference
   Dim blockInsert(0 To 2) As Double
   blockInsert(0) = 0
   blockInsert(1) = 0
   blockInsert(2) = 0
    
   If dblclickPoint(0) > 390000 _
   And dblclickPoint(0) < 395000 _
   And dblclickPoint(1) > 295000 _
   And dblclickPoint(1) < 300000 Then
       MsgBox ("You chosen the North West")
       Set mapBlock = ThisDrawing.ModelSpace.InsertBlock(blockInsert, "SO99NW", 1, 1, 1, 0)
       'Set mapBlock = ThisDrawing.ModelSpace.InsertBlock(blockInsert, "T:/SO99NW.dwg", 1, 1, 1, 0)
   End If
    
   If dblclickPoint(0) > 390000 _
   And dblclickPoint(0) < 395000 _
   And dblclickPoint(1) > 290000 _
   And dblclickPoint(1) < 295000 Then
       MsgBox ("You chosen the South West")
       Set mapBlock = ThisDrawing.ModelSpace.InsertBlock(blockInsert, "SO99SW", 1, 1, 1, 0)
       'Set mapBlock = ThisDrawing.ModelSpace.InsertBlock(blockInsert, "T:/SO99SW.dwg", 1, 1, 1, 0)
   End If
   
   AcadApplication.Update
   
   Me.Show

End Sub

I created two sqares in my drawing based on your coordinates and two blocks SO99NW and SO99NW.

 

In your code I changed your get point to:

 

   clickPoint = ThisDrawing.Utility.GetPoint(, "Select a point on map...")

and I changed twice

 

   And dblclickPoint(0) > 395000

to:

 

   And dblclickPoint(0) < 395000

I also added this line:

 

   AcadApplication.Update

 

to update the drawing and make the changes immediately visible.

 

Run the macro Maps, select one of the areas and it works just as expected.

 

It worked fine yesterday at home and it also works fine today in the office. I'm using AutoCAD 2012 and haven't testewd it on other versions, but there's nothing in there to stop it working on other versions.

Posted

When you click on a point, does it open the form again? because thats what happens to me.

Posted
When you click on a point, does it open the form again? because thats what happens to me.

 

Yes it does, but that's what your code implements with the Me.Show. But it inserts the block before it re-shows the form and if you then click in the other area it hides the form, inserts that block and then re-shows the form. If you don't want the form to show again after you have inserted your block then replace the Me.Show with End and that will quit your macro without re-showing the form.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...