Author Topic: Insert to metric/inch dwgs  (Read 2128 times)

0 Members and 1 Guest are viewing this topic.

Bryco

  • Water Moccasin
  • Posts: 1849
Insert to metric/inch dwgs
« on: June 20, 2006, 02:09:17 PM »
Having 2006 gives some nice options for setting the insert scaling. But we have both 2004 and 2006 so I need a way to be able to insert our standard reference bubbles etc into both inches and metric not using IAcadBlock3 properties.
I thought the following would work, by scaling the entities in a block if the drawing was metric but
Code: [Select]
Function isMM() As Boolean
    If ThisDrawing.GetVariable("Insunits") = 4 Then
        isMM = True
    End If
End Function

Function mmBlock(oBlock As AcadBlock)
    If isMM Then
        Dim Ent As AcadEntity
        Dim Ins
        Ins = oBlock.Origin
        For Each Ent In oBlock
            Ent.ScaleEntity Ins, 25.4
        Next
        oBlock.units = acInsertUnitsMillimeters
    End If
End Function

Alas 2006 decides to insert a block at 25.4  scale so the effects are doubled.

Any help appreciated.

Bob Wahr

  • Guest
Re: Insert to metric/inch dwgs
« Reply #1 on: June 20, 2006, 02:14:33 PM »
Just typed on the fly here so some tweaking is going to be needed fo sho but
Code: [Select]
Function is2k6() As Boolean
  If Left(thisdrawing.getvariable("ACADVER"),4) = "16.2" then
    is2k6 = true
  End if
end function

Bryco

  • Water Moccasin
  • Posts: 1849
Re: Insert to metric/inch dwgs
« Reply #2 on: June 20, 2006, 02:35:20 PM »
Thanks Bob I use the same thing.
Sometimes knowing what version doesnt stop the error
if is2k6 then
  dim B as IAcadBlock3
end if
this throws an error in 2004

Bob Wahr

  • Guest
Re: Insert to metric/inch dwgs
« Reply #3 on: June 20, 2006, 02:39:09 PM »
I see your problem.  You might have to run two different versions of the app.

Bob Wahr

  • Guest
Re: Insert to metric/inch dwgs
« Reply #4 on: June 20, 2006, 02:43:11 PM »
What about
Code: [Select]
Function mmBlock(oBlock As AcadBlock)
    If isMM Then
        Dim Ent As AcadEntity
        Dim Ins
        Ins = oBlock.Origin
        If not is2k6 then
            For Each Ent In oBlock
                Ent.ScaleEntity Ins, 25.4
            Next
        End If
        oBlock.units = acInsertUnitsMillimeters
    End If
End Function

Bryco

  • Water Moccasin
  • Posts: 1849
Re: Insert to metric/inch dwgs
« Reply #5 on: June 20, 2006, 04:12:36 PM »
So far that is a very good call Bob.

Bob Wahr

  • Guest
Re: Insert to metric/inch dwgs
« Reply #6 on: June 20, 2006, 04:15:18 PM »
Even a blind dog finds the radish sometimes.

Bryco

  • Water Moccasin
  • Posts: 1849
Re: Insert to metric/inch dwgs
« Reply #7 on: June 21, 2006, 12:17:13 AM »
Setting the units to inches and inserting the ref at a scale of 1 ends up with a ref scale 0.0394.
So inserting by vba with inch units in a metric dwg you need to use a scale of 25.4
whereas using sendcommand the scale is 1.
I've gone for below, not really knowing if there will be some long term ramifications.
Always Scale theents in the blocks for metric dwgs.
Code: [Select]
Function mmBlock(oBlock As AcadBlock)
    If isMM Then
        If AcadVer > 2004 Then
            oBlock.units = acInsertUnitsMillimeters
        End If
        Dim Ent As AcadEntity
        Dim ins
        ins = oBlock.Origin
        For Each Ent In oBlock
            Ent.ScaleEntity ins, 25.4
        Next
    End If
End Function

DaveW

  • Guest
Re: Insert to metric/inch dwgs
« Reply #8 on: June 21, 2006, 10:10:11 PM »
Do not know if it matters to you, but I have been using this number: 3.93700787401575E-02

Sorry I could not be of more help with the other problems. I still do not check the ACAD version. I am just reading your guy's stuff and hoping to learn what to do.


Bryco

  • Water Moccasin
  • Posts: 1849
Re: Insert to metric/inch dwgs
« Reply #9 on: June 21, 2006, 11:32:39 PM »
Dave  3.93700787401575E-02 is the same as 1/25.4
Does it matter?
My tests show 7.777x7.777 is faster than 7.777^2 and  7.777X0.5 is faster 7.777/2.
However scaling (at the command line) in cad wont allow 1/2.4 but does allow 10/254 which is easy to remember, so I'm used to using that now.

DaveW

  • Guest
Re: Insert to metric/inch dwgs
« Reply #10 on: June 22, 2006, 12:08:37 AM »
Setting the units to inches and inserting the ref at a scale of 1 ends up with a ref scale 0.0394.


I was reading that line and was thinking you were using that value. My bad.

What I learned from your response = my good.

Thanks. I am going to remember those tests of yours.

I am not really sure if it does matter for speed. I am usually only concerned with it working, with the hope that some day some poor programmer will fix it all for me, for payment of course. I never stopped and tried to add the fraction in VB. In theory, it should produce the same result. The time difference, unless noticeable, is a last concern.

My point was that using 0.0394 to scale with, vs. .039370078740157 may produce slightly different result. I am having to split hairs all the time, scaling from metric to imperial and back and so I went with the largest number I could find. I just misunderstood what you were saying. You are not using the value 0.0394, correct? It appears to me that your fraction may actually be a tad slower, but would probably produce the most accurate result, if one is more accurate to the other through VB.

PS. I am still trying to digest that stuff of yours on the first page of the swamp.
« Last Edit: June 22, 2006, 12:20:22 AM by DaveW »