cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

IsoDraw macro issue - help!

ptc-1524643
7-Bedrock

IsoDraw macro issue - help!

Hey up everyone - I'm hoping someone may be able to shed some light on a couple of problems I've run into...


1. I"m trying to develop a macro that will correctly format a batch of illustrations. So far everything's going to plan, but what I thought would be the easiest bit is proving the hardest. I want to use the 'fit to page' function, but I can't record it (the function is greyed out) and I can't find any reference in the help manual to script it either. Anyone done this before? After some digging it looks like this may only be a function available in 7.3 - I have 7.2, can anyone confirm?


2. I'm also trying to select any text which is less than 7pt. I have 2 different sizes on the illustration so I can't use the 'font_size is not' function.

I've been trying to develop a macro to select the smaller sized text and then lock it using the box.top and box.bottom parameters, but it fails to select the smaller size text, just the last piece of text on the illustration. It goes like this:


Macro Select text size

# recorded with Arbortext IsoDraw 7.2

DEFINE myElem AS Element

Select IF Type is equal to "Text"

myElem = activeDoc.firstSelectedElement

IF (myElem.box.top - myElem.box.bottom is smaller than 3) THEN

myElem.locked = 1

myElem = myElem.nextSelectedElement

END IF

End Macro


Anyone have any ideas why this doesn't work? In theory it should take the top box parameter and subtract the bottom box parameter of the first selected text element and if it's less than 3 (mm I'm guessing) it should lock it and move on to the next text element. All I get is that last text element locked (after a fashion) no matter what size it is.


Thanks for any ideas you may have.


Cheers


Rob

ACCEPTED SOLUTION

Accepted Solutions

Sorted it - after much wailing and nashing of teeth:

Select IF Type is equal to "Text"

el = activeDoc.firstSelectedElement

WHILE (Exists (el) = true)

a = el.box.top - el.box.bottom

IF (a < 6 - true) THEN

el.fill = color_black

END IF

el = el.nextSelectedElement

END WHILE

Select none

This routine fills the smaller text with a predefined colour (color_black) which I can then use as a selection criteria in future comands.

Thanks for your keen interest Trevor

View solution in original post

12 REPLIES 12

Hi Rob

I've a macro that we use to scale the drawing up to fill the page. I think the original came from Trevor Hendricks (so thanks) and I changed it to suit what we needed.

submacro Resize_to_Frame_Specify_Border NOT_IN_MENU

Define Height as Float

Define Width as Float

Define ScalePercentage as Float

Define BorderSize as Float

BorderSize = 10

#SELECT THE WHOLE DRAWING

select all

#Determines height and width of grouped art.

Height = gl_TopCoord - gl_BottomCoord

Width = gl_RightCoord - gl_LeftCoord

#Determines height and width of the Active Document Window and ratio between page size and geometry size so it knows how to work out scale percentage

define page_height as float

define page_width as float

define page_ratio as float

define geometry_ratio as float

page_height = ActiveDoc.window.pageY

page_width = ActiveDoc.window.pageX

page_ratio = page_height / page_width

geometry_ratio = height / width

if (page_ratio < geometry_ratio)

ScalePercentage = (ActiveDoc.window.pageY - bordersize) /(Height)

else

ScalePercentage = (ActiveDoc.window.pageX - bordersize) /(Width)

end if

Zoom Page

#NEXT MOVE THE DRAWING GEOMETRY TO THE CENTRE OF THE PAGE PRIOR TO SCALING IT

define geometry_centre_x as float

define geometry_centre_y as float

define page_centre_x as float

define page_centre_y as float

geometry_centre_x = (gl_leftCoord + ((gl_rightCoord - gl_leftCoord) / 2))

geometry_centre_y = (gl_BottomCoord + ((gl_TopCoord - gl_BottomCoord) / 2))

page_centre_x = (page_width / 2)

page_centre_y = (page_height / 2)

define MoveDistX as float

define MoveDistY as float

MoveDistX = (page_centre_x - geometry_centre_x)

MoveDistY = (page_centre_y - geometry_centre_y)

select all

move selection MoveDistX MoveDistY

#Scales the grouped art to proper size.

Scale Selection page_centre_x page_centre_y ScalePercentage ScalePercentage

Zoom Page

# CLEARS SELECTION

Select None

End submacro

---------------------------------------

The text bit, I just use subselect for text, or does that not do what you need?

select all

Subselect if Type is equal to 'text'

Subselect if Font_size is equal to 8

Hope this helps and I've not totally missed the point.

Tim,

Thanks for your help. I'll give the sizing macro a try. Seems a shame to go to so much code when all we really need is for 7.2 to support the 'fit elements' function as 7.3 does.

As for the text part - the problem I have is that the small text I'm trying to select does not conform to an exact size (eg. 8pt), and it is not always the same size. I have text that varies from 11.708 to 11.891. Hence I could do with a function that lets me select if text is less than 12pt, but life is not so easy. That's why I'm tring to use the element box height as a measure of the text size instead.

Thanks for trying.

Cheers

Rob

Oh yes I'm sorry I assumed there was a greater/less than option in subselect, but there isn't is there!

Could you attach a sample file (dumb it down if needed)?

mano
1-Visitor
(To:TimSharp)

Hi,

I used the same macro in 7.1, but it shows an error message as "Invalid command Height = gl_TopCoord - gl_BottomCoord

Does this command does not work in 7.1?

thendricks
12-Amethyst
(To:mano)

I believe I wrote that code while using 7.1 (we're now on 7.3). The problem appears to be that gl_TopCoord and gl_Bottom_Coord variables are not defined. Believe these need to be set as global if memory serves me correctly.

mano
1-Visitor
(To:thendricks)

need to be set as global? what is that?

Can you tell me one example?

thendricks
12-Amethyst
(To:mano)

I think you need to set the variable as global. Such a call would look like the following.

Global myVariable as String

As a side note, make sure to look over the macro help found under the help menu. There's a lot of good stuff in there. One thing that PTC is really good about is their documentation.

cara
4-Participant
(To:TimSharp)

I am trying to make object that is created to be made under a separate layer when generated. If the layer exist, then create is the prompt I am having issues with. Keep getting "if(exists(active layer 'ARROW'.name)=false) then" Error in expression syntax.

 

# recorded with Arbortext IsoDraw 7.2

define el as Element
define el2 as element
define spx as float
define spy as float
define epx as float
define epy as float
define ang as float
define ang2 as float
define xdef as float
define ydef as float
define div as float
define pt_end as point
define k as ColorSpec
define lyrNm as string

define me as MouseEvent 
define ptx1 as Point # x value of user selected point 
define pty1 as Point # y value of user selected point
define ptx2 as Point # x value of user selected point 
define pty2 as Point # y value of user selected point

if(exists(active layer 'ARROW'.name) = false) then
  add layer 'ARROW' .0
  activeDoc.Pens["LW_Medium"].name = "LW_Medium"
    end if

me = Wait MouseClick
        if (me.click = 0 || me.click = 1) then
            # left mouse pressed
            ptx1 = me.ptMM
            pty1 = me.ptMM
        end if   
me = Wait MouseClick
         if (me.click = 0 || me.click = 1) then
            ptx2 = me.ptMM           
            pty2 = me.ptMM
          end if 
           
Create line ptx1.x pty1.y ptx2.x pty2.y

k.type = "colorRef"
 k.color = "$ISO_BLACK"
 k.tone = 1.00
define myFill as fill
 myFill.type = "color"
 myFill.colSpec=k
define id_blue as ColorSpec
 id_blue.type = "rgbValues"
 id_blue.rgb.red = 128
 id_blue.rgb.green = 128
 id_blue.rgb.blue = 255
 if(exists(activedoc.pens["LW_Medium"].name) = false)then
  add pen "LW_Medium" .1
  activeDoc.Pens["LW_Medium"].screenColor = id_blue
  activeDoc.Pens["LW_Medium"].name = "LW_Medium"
  activeDoc.pens["LW_Medium"].switchPen = "LW_Medium"
 end if
 el = activeDoc.firstSelectedElement
 lyrNm = el.layer.name
 el.line.segments[1].pen = "LW_Medium"
 el.line.segments[1].halo = "Autom. Long"
 spx = el.line.startPoint.x
 spy = el.line.startPoint.y
 epx = el.line.segments[1].endPoint.x
 epy = el.line.segments[1].endPoint.y
 pt_end.x = epx
 pt_end.y = epy
 xdef = epx - spx
 ydef = epy - spy
 if(abs(ydef)<0.001)then
   ydef=0.01
  end if
 div = xdef / ydef
 ang = arctan(div)
 ang2 = 90 - ang
 if(ydef < 0)then
  ang2 = ang2 + 180
 end if
 activate layer lyrNm
 el2 = create line spx spy (spx + 2.55) (spy + .45)
 el2.line.segments[1].pen = "LW_Medium"
 append line segment (spx + 2.5) spy
 el2.line.segments[2].pen = "LW_Medium"
 append line segment (spx + 2.55) (spy - .45)
 el2.line.segments[3].pen = "LW_Medium"
 append line segment spx spy
 el2.line.segments[4].pen = "LW_Medium"
 rotate selection spx spy ang2
 el2.fill = myFill
 SELECT NONE
# Set active pen "LW_Medium"
 Activate Layer "New Raster"
# Zoom extent
# Zoom page
# Set active pen "LW_Medium"
# SELECT NONE
 
End Macro

Sorted it - after much wailing and nashing of teeth:

Select IF Type is equal to "Text"

el = activeDoc.firstSelectedElement

WHILE (Exists (el) = true)

a = el.box.top - el.box.bottom

IF (a < 6 - true) THEN

el.fill = color_black

END IF

el = el.nextSelectedElement

END WHILE

Select none

This routine fills the smaller text with a predefined colour (color_black) which I can then use as a selection criteria in future comands.

Thanks for your keen interest Trevor

Just a late follow up, but something to think about. I personally try to avoid visual modifications as there may be a failure or something missed. Another approach versus the color would be to apply some object info metadata. Something to keep in mind for next time. The code below is an UNTESTED modification of the accepted code.

Select IF Type is equal to "Text"

el = activeDoc.firstSelectedElement

WHILE (Exists (el) = true)

a = el.box.top - el.box.bottom

IF (a < 6 - true) THEN

Create object_info el

el.Info.Name = "here I am"

END IF

el = el.nextSelectedElement

END WHILE

Select none

Trevor,

A late follow up to your late follow up...

That makes absolute sence, don't know why I didn't think of it myself. Thanks for taking the time to give it some thought.

Cheers

Rob

Announcements

Top Tags