View Full Version : [SLEEPER:] Stretching Dimensions via VBA

01-07-2009, 10:30 AM
I'm trying to figure out how to "stretch" a dimension via Code. I've placed some objects and then dimensions. I want to be able to move those objects to a new location updating the dimensions as well. What happens is that the entire dimension moves not just the control pts @ the object. I've tried all sorts of selection set filter codes but no luck.

fcode(0) = -4: ftype(0) = "<and"
fcode(1) = -4: ftype(1) = "<or"
fcode(2) = 0: ftype(2) = "INSERT" ' block I want to move
fcode(3) = 0: ftype(3) = "Dimension" ' dimension(s) at the block location
fcode(4) = -4: ftype(4) = "or>"
fcode(5) = -4: ftype(5) = "<not"
fcode(6) = 14: ftype(6) = vupperright ' don't move one side of a dimension
fcode(7) = 13: ftype(7) = vupperleft ' don't move another side of a different dimension
fcode(8) = -4: ftype(8) = "not>"
fcode(9) = -4: ftype(9) = "and>"

This selection set here gives me an error about invalid procedure call

Here is the remaining code...if I just use the <or INSERT Dimension or> then
everything moves including the line

On Error Resume Next
On Error GoTo 0
Set objss = ThisDrawing.SelectionSets.Add("HandleSelection")
objss.Select acSelectionSetCrossing, pt1, pt2, fcode, ftype
For Each objSelection In objss
objSelection.Move vOldPT, HandleLocPT

Any ideas, work arounds....:banghead:

01-07-2009, 06:05 PM
Hi RickyD302,

fcode(2) = 0: ftype(2) = "INSERT," ' block I want to move

Add a comma after the INSERT, that may be what it is looking for.

I am not sure what you are talking about on the dimensions. Could you zip a drawing with what you have and what you want? Also a dimension has properties that you can manipulate just like any other object. This may be a case of which property needs to be changed. :dunno

01-07-2009, 09:00 PM
What I've done is create a application where a user builds his handle scheme via a VBA form. He then places that scheme in the drawing. The handles are dynamic blocks that are placed a calculated locations. I then dimension the "handle" locations. I'm wanting to allow the user to edit those locations later if need be. If the drawing changes by length or width then recalculations need to be done and then the handles need to move to the new locations. I've not be able to ps z e associate the dimension via VBA so I want to move the handles and have the dimension update. I can find the handle since it is a block.
I've attached the drawing to reflect what I'm talking. I look forward to your ideas.

01-08-2009, 09:19 AM
Yea Tommy,
I think I need to get the right control points of the dimension to move but I can't seem to get my selection set correct. When I move pass

fcode(0) = -4: ftype(0) = "<or"
fcode(1) = 0: ftype(1) = "INSERT,"
fcode(2) = 0: ftype(2) = "Dimension"
fcode(3) = -4: ftype(3) = "or>"

Then I start getting invalid procedure call.

fcode(0) = -4: ftype(0) = "<and"
fcode(1) = -4: ftype(1) = "<or"
fcode(2) = 0: ftype(2) = "INSERT,"
fcode(3) = 0: ftype(3) = "Dimension"
fcode(4) = 100: ftype(4) = "Dimension"
fcode(5) = 2: ftype(5) = "*D"
fcode(6) = -4: ftype(6) = "or>"
fcode(7) = -4: ftype(7) = "<not"
fcode(8) = 13: ftype(8) = vupperleft
fcode(9) = 14: ftype(9) = vupperright
fcode(10) = -4: ftype(10) = "not>"
fcode(11) = -4: ftype(11) = "and>"

I know this isn't right but what I'm trying to do is grab the dimension then
exclude the points I don't want to move. This is what I need to do correct?

01-08-2009, 11:40 AM
After reviewing the drawing I would have to say no. You will need to select the dimensions and then change the properties.

fcode(0) = 0: ftype(0) = "INSERT,Dimension"
The above code will set the selection set to select INSERT and Dimension objects only. Now you will need to sort them according to the locations to the inserts I would think. Then move the ExtLine1Point or ExtLine2Point, then do an update for the dimension to update the information.

01-08-2009, 12:13 PM
are these exposed in VBA......do I search for them...could you provide a some code on what your thinking I'll change my code to reflect "insert,dimension" and see if I can get further. Thanks Tommy

01-09-2009, 07:12 AM
Much to my regret I am finding that when the dimension object is caputured it will not give up the ExtLine1Point and ExtLine2Point. I have now tried it 4 different ways, still no joy. I've tried selection sets and I've tried the loop throught the dimensions and I have even tried to use the handletoobject method. I may be able to get to it with a lisp and vba solution but am not sure at this point, I do know it can be done in lisp. A lot of things are exposed in lisp that are not exposed in vba for some reason. I will continue to try to find a solution.

01-09-2009, 07:34 AM
I did find this that will expose the points

I can't show the link because I dont' have enought post
but here it is h t t p : / / discussion.autodesk.com/forums/message.jspa?messageID=5736419
I'm not sure if this will do what I want ......

but I'm getting a "Problem in loading application" error when I

Function GetVl() As Object
Application.LoadArx "VL.arx"
Dim VLisp As Object
Set VLisp = ThisDrawing.Application.GetInterfaceObject("VL.Application.17")
Set GetVl = VLisp
End Function

Let me know what you think!

01-09-2009, 01:28 PM
The link you posted was great! I can modify any dimension I pick however I want.

But I have to pick it. Am still working on it though. I am severly stuck on the GetSubEntity I need this to get the OwnerId to get the block name that is for the dimension. Once I can get this it is mine :)

Just a staus report.

Anything yet at TekForum?

01-09-2009, 01:44 PM
I've had some but they were the obvious ones like you need to move just the dimenion pts not the whole dimension. This is where I got hung up on was how to get around the getsubentity. There is a subentity class but it says its internal so....... If and when I get something I will pass it on for sure. thanks Tom.
Another problem I'm having is that I can't load the VL.application.17
I'm using 2009 mechanical and everything I've tried gives me "problem loading application" Any ideas on that one? I've actually posted this question in the Autodesk forums.

01-09-2009, 03:02 PM
at this link:

I found the attached file.

Function GetVl() As Object
Application.LoadArx "VL.arx"
Dim VLisp As Object
Set VLisp = ThisDrawing.Application.GetInterfaceObject("VL.Application.16")
Set GetVl = VLisp
End Function

Sub ab()
Dim al As Object
ThisDrawing.SendCommand "(vl-load-com) "
Set al = GetVl
End Sub

I got pasted all the error messages and I haven't tried to do anything else. The key is the .17 I had to change it to .16 I am using AutoCAD2007.

01-09-2009, 09:28 PM
I will look at this class.....compiled alright but now to figure out what I have.

01-09-2009, 09:32 PM
When I changed it to 17 I received an error but leaving @ 16 loaded alright.... Gotta love computers!

01-10-2009, 09:30 AM
Now that I can get to the end points How do I move them......Please understand that I am new to all this.

01-12-2009, 06:54 AM
If you have the endpoints change to suite what you need.
Keep in mind I don't know how you have selected the correct dimension to change.

01-12-2009, 10:40 AM
I do this based on the point where the handle block is. I'm needing to move that block and control pt to a new location without moving the other control point of the dimension.

01-12-2009, 12:11 PM
Do you know the location or does it change for each block?
Can I see the code you have so far for selecting the dimension?
So far as the block it would be to change the insertion point to what you need, then you could add the difference to the adjustment to the dimension. Once you have the points you can check to see which on is in line with the block insertion point by checking the X and Y values. Then modifing the one that needs the change or vacation. LOL

01-12-2009, 12:58 PM
I have the where the handle was and where it will go so I have the neceassry information to move the handle to the correct location. What I'm having troubles with is stretching the dimension. When I selected the dimension and then do
"object.move oldpt newpt" it would take the entire dimension with it. Now with the code you provided I'm trying to figure out what do do with it. I see that this code will give me the control points (DXF code 13 & 14) but this is where I start getting lost!

01-13-2009, 06:59 AM
Then why can't you move the block, delete the dimension and recreate it? I know that is not what you want to do but it may be faster and easier.:dunno

01-13-2009, 07:23 AM
I thought about that......I got everything to work by using the sendcommand. I create a small crossing window that picks up the block and dimensions.
If I delete the dimensions then I'll have to have use select the dimension location when I re-dimension. I'm going to keep playing with trying to stretch the dimension just so I can say I figured it out but I was able to get my handle routince to work by using the sendcommand. Thank Tommy

01-13-2009, 08:02 AM
I will still be trying just because I don't know how. FWIW :)

01-13-2009, 02:25 PM
I'm thinking about going thru and removing the dimension and before I do I'll get the location of the dimension line that I can pass to my dimension routine. I just didn't figure on passing variants to the dimension routine. It sure would be nice to be able just to stretch the darn thing. You'd think Autodesk could shed some insight.....

01-15-2009, 09:12 AM
I ended up re-writing the routine to delete the dimension grabbing the dimension line location and then writing back the dimension after moving the blocks. Took alot more code but seems to work a little faster and I have more control this way.
I messed around with getting the dimension parent object which is a block and tried to mess with that...no luck

01-15-2009, 11:30 AM
Thank you. I will still be playing with it, will post back if I can find a way.

01-15-2009, 12:05 PM
Sounds good the VbAssoc() worked well with getting information about the dimrotated object but I didn't see where I could change it. To bad theres not a move point command