GETPOINT Fails error If I switch to another drawing in my VBA application

GETPOINT Fails error If I switch to another drawing in my VBA application

Anonymous
Not applicable
7,479 Views
23 Replies
Message 1 of 24

GETPOINT Fails error If I switch to another drawing in my VBA application

Anonymous
Not applicable

 

To place a drawing into another location using ALIGN I use an overall OS coordinate system drawing to get matching points to place the first drawing.

 

Both drawings are loaded into AutoCAD


I've created a combobox to switch drawings whilst my application is running and even ACTIVATE and REGEN the selected drawing:

ThisDrawing.Application.Documents.Item(ComboBox1.ListIndex).Activate
ThisDrawing.Application.Documents.Item(ComboBox1.ListIndex).Regen acAllViewports

The GETPOINT line is only successful in the drawing that was active BEFORE I started my application and Fails in the other activated drawing:

The error I get in all other drawings I select and activate:



Anyone any idea what's need to be set before I can use it in the newly activated drawing?

Thanks

 

0 Likes
Accepted solutions (1)
7,480 Views
23 Replies
Replies (23)
Message 2 of 24

Anonymous
Not applicable

you most probably have your macro embedded in the drawing you start your macro from

just change "ThisDrawing" (which, in that scenario, would always point to the drawing where the macro is embedded in)  to "ActiveDocument" (which points to the currently active drawing)

 

PrikPnt = ActiveDocument.Utility.GetPoint(basePnt, PrikPointTExt)

but, much better, you'd not rely on the "ActiveDocument" reference since you could easily "loose" it (you'd bet it is myDoc1 while it actually is another one!) during a sufficiently long code and/or user selection, and use properly set document objects references instead:

 

Dim myDoc1 as AcadDocument, myDoc2 as AcadDocument

Set myDoc1 = Application.Documents("Drawing1.dwg")
Set myDoc2 = Application.Documents("Drawing2.dwg")

myDoc1.Utility...

myDoc2.Modelspace.AddLightWeightPolyline(...)

 

0 Likes
Message 3 of 24

Anonymous
Not applicable

Hi RICVBA,

 

Thanks for your message.

 

Both didn't solve the problem unfortunately, same error still occurs when I use:

 

(ActiveDoc - 1 points to the right index)

 

Dim ActiveDoc1 As AcadDocument

 

Set ActiveDoc1 = Application.Documents.Item(ActiveDoc - 1)

PrikPnt = ActiveDoc1.Utility.GetPoint(Basepnt, PrikPointTexT)

 

 

And using:

 

 

ActiveDocument instead of ThisDocument

 

 

Not sure what's going on as I agree with you that pointing to the exact Doc should work.

 

Thanks anyway,

 

0 Likes
Message 4 of 24

Anonymous
Not applicable

As you already showed in your first post, you have to first activate the document and then use GetPoint() method upon it

 

Dim ActiveDoc1 As AcadDocument
 
Set ActiveDoc1 = Application.Documents.Item(ActiveDoc - 1)
ActiveDoc1.Activate
PrikPnt = ActiveDoc1.Utility.GetPoint(Basepnt, PrikPointTexT)

or, in a (perhaps) more elegant way:

With Application.Documents.Item(ActiveDoc - 1)
    .Activate
    PrikPnt = .Utility.GetPoint(Basepnt, PrikPointTexT)
End With

 

 

 

0 Likes
Message 5 of 24

Anonymous
Not applicable

Hi RICVBA,

 

Thanks for your reply.

 

Again, unfortunately both applied give the continuous error:

 

If I watch the Application.Documents.Item(ActiveDoc - 1) state it shows that it is Active and with the correct file because in a combobox prior to calling the routine I also activate the selected drawing and ModelSpace is active to be able to point in it. 

 

error2.jpgerror3.jpg

Not sure where to look for as I've used both your ideas.

 

I've even used DoEvents in the selection of drawings to ensure all other activities are granted.

 

It seems to me that it somehow locks the other drawings for use when I start the VBAapplication.

 

Start the application, collect the points in the active drawing, stop the application, switch drawings, start the application to use the points works fine.

 

All ideas are welcome and will be looked into.

 

0 Likes
Message 6 of 24

Anonymous
Not applicable

in my "environment" the code I posted lets me switch between drawings via a UserForm and allows the user to GetPoints()

my "environment" is:

- my VBA routine is loaded in AutoCAD

- my VBA routine is launched through ALT+F8 and then selecting the macro

- my VBA routine doesn't launch/catch/try activating any other application object (like Excel or so)

- I'm using AutoCAD 2014 in Windows7 SP1

- my VBA routine does what follows:

  - launches a Userform which has:

     - a combobox to let the user select the drawing

     - a ComboBox1_Change() event to check for valid ListIndex and then calling a sub to activate the proper drawing

     - a button to let the user leave (hide) the Userform

  - calls the GetPoint method on the ActiveDocument 

 

you may want to compare this environment to yours and let me know the differences/details

 

0 Likes
Message 7 of 24

norman.yuan
Mentor
Mentor

You did not mention, but I assume you use AutoCAD 2015 or later.

 

I think this is because of AutoCAD 2015's change (remove FIBER) that when active document changes, current active command would be cancelled. When Autodesk intruduced this change in AutoCAD 2015, it broke quite some existing CAD programs, be they list/VBA/.NET ones. Wihle VBA macro may behave a bit different from AutoCAD command, it suffered the same with the AutoCAD 2015 change when the code execution needs switch active document.

 

RICVBA replied the similar code worked on his side, it is because of he is still using AutoCAD2014.

 

I am afraid you need to re-design yiour program's workflow to obtain data from other drawing, in order to bypass the requirement of switch active document (for example, you can still go through the entities in an opened source drawing without making it active).

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 8 of 24

Anonymous
Not applicable

Thanks norman.yuan,

 

Yep, correct, did not mention that I was working in AutoCAD 2016, 2017 and 2018.

 

And was afraid that there was a sort of drawing switching problem going on.

 

Going through the entities of a non opened, non active drawing is not an option as I need the user to interact (pointing to a point) and get the dedicated info from an active drawing.

 

Thanks a lot for the info, at least I can work with it old style and switch drawings outside my applications. I know now to use the workaround method.

 

Knowing not to pull my hair out for not finding the logic behind an issue.

 

Take care and stay safe.

0 Likes
Message 9 of 24

Anonymous
Not applicable
Can you explain in more detail why you need to run commands between drawings? May be there's a way to avoid this by storing info from each of them and then come back to the "main" drawing to exploit those info to run the final command


While getting back to the Fibers that Norman explained, maybe you can still switch back to the pre2015 behaviour (see http://through-the-interface.typepad.com/through_the_interface/2014/03/autocad-2015-for-developers.h...) using NEXTFIBERWORLD and FIBERWORLD system variables
0 Likes
Message 10 of 24

Anonymous
Not applicable

Hi RICVBA,

 

In setting out in construction the part job of a SO Engineer is to place all drawings in an overall Construction Position Coordinate System which envelopes the entire project.

 

Detail drawings from architects and engineers are supplied in a local, unrelated coordinate system with grid lines as the only matching resemblance between the two.

 

In my application I want the user to point to three matching grid line intersection points in the overall CPCS grid lines drawing, place them on the clipboard, switch to the local architect/engineers drawing and point to the same three points to be able to use ALIGN (retrieving the clipboard coordinates as the final points) in the local drawing to place it into the CPCS coordinate system incl. scaling (mm to m. or other strange scale units to m.)

 

Once the local drawing is positioned I use the third point as a check to see if all in the 2D repositioning of the local drawing has gone well.

 

Once that QC check has been successful a 3D drawing will be lifted to the correct datum using 1 point as a reference but this is not always the case in supplied construction detail drawings, 3D modelling as a base has not entered the world of construction here alas .....

 

Hope this clears the air in my goal.

 

 

0 Likes
Message 11 of 24

Anonymous
Not applicable

I think I got your needs

 

And from previous posts I got that your issue is strictly related to the inability of AutoCAD 2016 or higher VBA to switch between drawing while a command (namely "ALIGN") is active

 

so just a shot: maybe you could first have the user select all needed points switching between relevant drawings and store their coordinates and then run the ALIGN command through SendCommand() method?

 

 

0 Likes
Message 12 of 24

Anonymous
Not applicable

Thanks RICVBA,

 

that's correct: from 2016 onwards it seems that switching between drawings whilst running a VBA routine/command is not possible.

 

Your suggested shot is exactly what I've made before and that worked well.

 

It requires some instruction to the user but it works well using the clipboard as the means of transfer to get the other drawing ALIGNed.

 

I'm fairly happy with that solution but wanted to switch between drawings to make the workflow smoother.

 

Thanks for your help anyway 

0 Likes
Message 13 of 24

Anonymous
Not applicable

well, my shot was about actually letting the user switch between drawings

in more detail:

1) the macro starts

2) it asks the user to switch between drawings by means of choosing them in some listbox/combobox

    of course the user must be instructed about which points to select and in which order

3) upon each selection the macro stores the points coordinates in some (variant or double()) variables

4) after the user is done with selecting points the macro issues all needed SendCommand()s, each with proper parameters taken from the "storage" variables

 

would that be an option?

0 Likes
Message 14 of 24

Anonymous
Not applicable

RICVBA,

 

That's exactly what I've built but it doesn't work in ACAD 2016 and higher. See my initial start of this tread here.

 

When starting a VBA application I can select and switch drawings as you proposed, even set them Active but during the session it doesn't allow to use GetPoint() in the drawings that were not active when I start the application:

 

error 4.jpg

 

It works only in the drawing that was active when I started the application.

 

I've used ThisDocument.Utility.... and ThisDrawing.Utility..... all in the correct way but no change in the error unfortunately.

 

Is there another way to refer to the AutoCAD session instead of ThisDrawing / ThisDocument to avoid pointing to one document/drawing ?

 

0 Likes
Message 15 of 24

Anonymous
Not applicable

I see it now (at last!)

while not having AutoCAD 2015 I cannot test if there's some solution (if any)

have you tried setting NEXTFIBERWORLD and FIBERWORLD system variables on and off?

 

otherwise I can only think of a workaround like:

1) have the user "mark" all the relevant points in all relevant drawings

    for instance the "marking" could be made add point objects in some "dedicated" layer,

    to make this step a little "automatic" you could have the user switch manually between all relevant documents and, while in any current one, call a "little" macro by which she would select all relevant points in that document and have the macro "mark" them by adding points object in any "dedicated" layer

2) run the "main" macro that would

    - ask the user to select relevant drawing (in the proper sequence, if necessary) by means of some list/combobox

      or maybe it could suffice just to specify the "main" drawing and automatically inferring all other open documents are the "slave" ones

    - ask the user to specify the layer name of the dedicated layer

      or maybe just assume a default one and skip this step

    - switch between all drawings and:

      . collect "marked" points by means of selectionset object and run the needed ALIGN method

  

0 Likes
Message 16 of 24

Anonymous
Not applicable

Thanks RICVBA.

 

I will give the "have you tried setting NEXTFIBERWORLD and FIBERWORLD system variables on and off?" a shot and get back to you.

 

[EDITED]

Just checked the systemvar NextFiberWorld and FiberWorld, both were set to 0 initially. I can set FiberWorld to 1 but it doesn't allow NextFiberWorld to be set to 1.

 

Setting FiberWorld to 1 does not resolve the problem. Are there more options for both (-1 or so). I can't find any reference to what they do so am in the dark here.

 

What do they control ?

 

0 Likes
Message 17 of 24

Anonymous
Not applicable

I'm in the dark with NEXTFIBERWORLD and FIBERWORLD as much as you are, since I never used them

I only saw they were mentioned with AutoCAD 2015 issuing as "somehow" connected to the Fiber technology which, on its turn, was "somehow" connected to the active document handling...

So I can't help you further this way

 

What about the proposed workaround? have you considered it?

0 Likes
Message 18 of 24

Anonymous
Not applicable

@Anonymous have you checked this post?

I don't have AutoCAD 2015 so can't test it myself

0 Likes
Message 19 of 24

arjenbroens
Explorer
Explorer

Hi RICVBA,

 

Tried and tested in ACAD 2016 but unfortunately even with my base drawing as the only existing drawing AND set to be ACTIVE GETPOINT still comes with the same error.

 

Workflow:

 

Open AutoCAD => start application => Close all existing drawings if any => open the base drawing to get coordinates from => set it to be active and hence is the only one existing => use the Thisdrawing.Utility.GETPOINT (and alternatives) to point to the base points and it fails on the first GETPOINT with the same error message as it did in my previous attempts.

 

It won't allow switching active drawings in a VBA session although all signs are there that the chosen drawing IS active and even the only existing drawing.....Unfortunately you cannot run the application without opening a Drawing1.DWG first unless I'm missing something as applications are drawing based and not AutoCAD sessions based (?).

 

 

So,... decided to leave the matter and go back to my initial solution: open my application to collect points in the base drawing => close my application, let the user manually switch to the unALIGNed drawing and start my application again to proceed the process with the points either from the clipboard or from a temp file and ALIGN this drawing and check with 3 circles placed on the base points to see if the process has been successfull.

 

That works but the user needs instructed what to do between application settings unfortunately ...

 

Thanks for your assistance and time to look into this.

 

A.

0 Likes
Message 20 of 24

Anonymous
Not applicable

have you already tested the solution given in post #4 in The Link I included in my previous post?