SketchUp 8 Constants Guide
SketchUp defines constants, some are global, others are defined in classes or 'namespaced'. Many of them are not listed in the SketchUp.com help documentation. This list includes all constants.
While creating this document, I noticed that some constants' values changed from version to version. Hence, it is strongly recommended that the constant names (versus their values) are used in code.
All of the links in this reference refer back to SketchUp.com.
Some of the concepts in this document may be obvious to experienced programmers, but many API users are new to Ruby, or new to programming.
Finally, thanks to Jim Foltz and others for their previous work and help.
Generated with SUMD_Guide v2.0, on 2015-12-21 at 04:27:34 PM GMT, using SketchUp v8.0.16846 & Ruby v1.8.6.
Unless otherwise noted, constants are of class Fixnum.
This document divides the SketchUp defined constants into three categories
1. Namespaced Constants: These are defined on a class. They will often be listed in a form similar to:
Sketchup::Importer::ImporterNotFound
Sketchup::Importer
is the class they are defined on. Hence, one can set a
variable equal to the class, and refer to them in another way. A short name may
make the code more readable.
# cns = constant namespace
cns = Sketchup::Importer
if (t == cns::ImporterNotFound)
# etc
end
Two things to remember about namespaced constants:
- One can define the namespace, but one can also use the class method on an instance object.
- They are inherited. If they are defined on a class (like 'Dimension'). They are also available on its subclasses (like 'DimensionLinear').
2. Global Numeric Constants:
Almost all of these constants are used as parameters or returns in methods. Most are Fixnum.
3. Global Object Constants:
There are a few constants that are SketchUp objects. All are defined in the Geom module, with the exception of Sketchup::Console.
Namespaced Constants
Dimension #arrow_type #arrow_type=
Defined on Sketchup::Dimension. See Dimension#arrow_type. These constants are for use with Sketchup::Dimension subclasses such as DimensionLinear and DimensionRadial.
arrow_type = dim.arrow_type
dim.arrow_type = arrow_type
** Constants not defined in SketchUp 8 **
DimensionLinear #aligned_text_position #aligned_text_position=
Defined on Sketchup::DimensionLinear. See DimensionLinear#aligned_text_position.
at_pos = dim.aligned_text_position
dim.aligned_text_position = at_pos
** Constants not defined in SketchUp 8 **
DimensionLinear #text_position #text_position=
Defined on Sketchup::DimensionLinear. See DimensionLinear#text_position.
text_pos = dim.text_position
dim.text_position = text_pos
** Constants not defined in SketchUp 8 **
Entities #add_faces_from_mesh
Defined on Geom::PolygonMesh. See Entities#add_faces_from_mesh.
ame = Sketchup.active_model.entities
ame.add_faces_from_mesh(pm, smooth_flags, material)
** Constants not defined in SketchUp 8 **
Face #classify_point
Defined on Sketchup::Face. See Face#classify_point.
pt_location = face.classify_point(pt)
The below code sample is in the template_code.rb file. Load, then SUMD_TC.new.face_1.
# must have a model open with at least one face!
cns = Sketchup::Face
face = Sketchup.active_model.entities.grep(cns)[0]
if (face)
pt_location = face.classify_point(ORIGIN)
t = case pt_location
when cns::PointInside then 'pt is inside'
when cns::PointNotOnPlane then 'pt not on plane'
when cns::PointOnEdge,
cns::PointOnVertex then 'pt on perimeter'
when cns::PointOutside then 'pt is outside'
when cns::PointUnknown then 'pt error?'
else 'not trapped by case statement'
end
else
t = 'no face found'
end
puts t
pt_location | value | pt_location | value | |
---|---|---|---|---|
PointInside | 1 | PointOnVertex | 2 | |
PointNotOnPlane | 32 | PointOutside | 16 | |
PointOnEdge | 4 | PointUnknown | 0 | |
PointOnFace | 8 |
Importer #load_file
Defined on Sketchup::Importer. See Importer#load_file. These are returned to SketchUp when your importer is finished with processing. Note the following is not included --
5 = SketchUp version not supported (no additional dialog shown)
class YourImporter < Sketchup::Importer
def load_file(file_path, status)
return status_code
end
end
status_code return | value |
---|---|
ImportCanceled | 2 |
ImportFail | 1 |
ImportFileNotFound | 4 |
ImportSuccess | 0 |
ImporterNotFound | 3 |
Length 'UnitsOptions' OptionsProvider
Defined on Length. See Model#options, OptionsManager, OptionsManager#[] and OptionsProvider.
First, SketchUp.com does not list all of the keys used in OptionsManager and OptionsProvider. The below table shows all of the keys.
OptionsManager key | OptionsProvider key | OptionsProvider value | class |
---|---|---|---|
PageOptions | ShowTransition | true | Boolean |
TransitionTime | 2.0 | Float | |
PrintOptions | ComputeSizeFromScale | false | Boolean |
FitToPage | true | Boolean | |
LineWeight | 0.5 | Float | |
ModelExtents | true | Boolean | |
NumberOfPages | 1 | Fixnum | |
PixelsPerInch | 150.0 | Float | |
PrintHeight | 11.0 | Float | |
PrintQuality | 0 | Fixnum | |
PrintWidth | 8.5 | Float | |
ScaleAdjustment | 1.0 | Float | |
SectionSlice | false | Boolean | |
SizeInModel | 1.0 | Float | |
SizeInPrint | 1.0 | Float | |
VectorMode | false | Boolean | |
SlideshowOptions | LoopSlideshow | true | Boolean |
SlideTime | 1.0 | Float | |
UnitsOptions | AnglePrecision | 1 | Fixnum |
AngleSnapEnabled | true | Boolean | |
ForceInchDisplay | false | Boolean | |
LengthFormat | 1 | Fixnum | |
LengthPrecision | 4 | Fixnum | |
LengthSnapEnabled | true | Boolean | |
LengthSnapLength | 0.25 | Float | |
LengthUnit | 0 | Fixnum | |
SnapAngle | 15.0 | Float | |
SuppressUnitsDisplay | false | Boolean |
These constants are used with the 'UnitsOptions' OptionsProvider. In the two following code lines, units and format have constant equivalents.
am = Sketchup.active_model
units = am.['UnitsOptions']['LengthUnit']
format = am.['UnitsOptions']['LengthFormat']
The following code creates two hashes that make use of the Length:: constants, queries the two settings, and outputs to the console. It's in the template_code.rb file. Load, then SUMD_TC.new.len_1.
cns = Length
h_units = Hash.new('Unit Unknown')
h_format = Hash.new('Format Unknown')
h_units[cns::Centimeter] = 'cm'
h_units[cns::Feet] = 'ft'
h_units[cns::Inches] = 'in'
h_units[cns::Meter] = 'm'
h_units[cns::Millimeter] = 'mm'
h_format[cns::Architectural] = 'Architectural'
h_format[cns::Decimal] = 'Decimal'
h_format[cns::Engineering] = 'Engineering'
h_format[cns::Fractional] = 'Fractional'
om = Sketchup.active_model. # OptionManager
op = om['UnitsOptions'] # OptionsProvider
units = h_units[ op['LengthUnit'] ]
format = h_format[ op['LengthFormat'] ]
puts "Current model units are #{units}"
puts "Current model format is #{format}"
constant | value | constant | value | |
---|---|---|---|---|
Architectural | 1 | Fractional | 3 | |
Centimeter | 3 | Inches | 0 | |
Decimal | 0 | Meter | 4 | |
Engineering | 2 | Millimeter | 2 | |
Feet | 1 |
Model #save #save_copy
Defined on Sketchup::Model. See Model#save and Model#save_copy.
# version param +2014, if omitted, saves in current version
status = model.save(filename, version)
status = model.save_copy(filename, version)
** Constants not defined in SketchUp 8 **
RenderingOptionsObserver
Defined on Sketchup::RenderingOptions. These constants are used with a RenderingOptionsObserver instance (fqn Sketchup::RenderingOptionsObserver).
A RenderingOptions instance is essentially a Hash. Its keys can be enumerated, and setting their value will change the rendering options of the model. The constants are used in a callback method in a RenderingOptionsObserver instance as a notification of rendering option changes by the user or other code.
The constants provide some information about the change.
- They do not map one-to-one to the RenderingOptions keys. Some changes will result in two callbacks firing.
- Some RenderingOptions keys will fire a callback, but with no constant assigned to the type value.
- Some RenderingOptions keys will not fire a callback.
The following code lists all of the RenderingOptions constants and values, then creates a hash from all of the RenderingOptions keys. It then adds a RenderingOptionsObserver to the current model. The observer outputs to the console the onRenderingOptionsChanged callback's type parameter and the constant associated with it, along any RenderingOptions changes. One can change RenderingOptions thru the UI and see what's going on, especially if UI operations do not have constants or keys. The code sample is in the template_code.rb file. Load, then SUMD_TC.new.ro_1.
am = Sketchup.active_model
cns = Sketchup::RenderingOptions
# create a hash of ro keys
@@h_ro = {}
am..each { |k,v|
val = v.kind_of?(Sketchup::Color) ? v.to_s.slice(-20,20) : v
@@h_ro[k] = val
}
# hash @@roc = RenderingOptions constants
# key is constant value
# value is constant name, with some spacing added by RegEx
@@roc = Hash.new("** No Constant! **")
# get all the constants, parse names, add to hash
cns.constants.each { |c|
text = c.to_s.dup
if ( text =~ /^ROPSet/ ) ; text.sub!(/^ROPSet/, 'ROPSet ')
elsif ( text =~ /^ROP/ ) ; text.sub!(/^ROP/ , 'ROP ')
end
@@roc[cns.const_get(c)] = text
}
# dump hash to console
cnsl = '-----------------------------------------'
puts cnsl + ' ro_1()'
prev = -1
@@roc.sort.each { |r|
num = r[0].to_s.rjust(3) + ((prev + 1 != r[0]) ? "*" : " ")
puts "#{num} #{r[1]}"
prev = r[0]
}
puts cnsl
# create a RenderingOptionsObserver instance & add callback method
@obs_ro1 = Sketchup::RenderingOptionsObserver.new
@obs_ro1.instance_eval {
@tmr_stopped = true
def onRenderingOptionsChanged(ro, type)
# timer puts line breaks between ro changes when multiple ocurr
if (@tmr_stopped)
@tmr_stopped = false
UI.start_timer(0.100) { @tmr_stopped = true ; puts }
end
# Loop thru ro's and find changes, load into s_val
s_val = ''
ro.each { |k,v|
val = v.kind_of?(Sketchup::Color) ? v.to_s.slice(-20,20) : v
if (@@h_ro[k] != val)
@@h_ro[k] = val
val = "%e" % v if (v.class == Float)
s_val << "#{val.to_s.rjust(20)} #{k}"
end
}
# finally put info to console
puts "#{type.to_s.rjust(2)} #{@@roc[type].ljust(32)} #{s_val}"
end
}
# attach the observer
am..add_observer(@obs_ro1)
The above code does not make use of the constants, so the below code shows one way of creating an observer. The callback uses some constants (items in 'view' menu and toolbar) in a case statement. Similar code could be used in a plug-in. This code sample is SUMD_TC.new.ro_2.
# create an observer & add callback method
@obs_ro2 = Sketchup::RenderingOptionsObserver.new
@obs_ro2.instance_eval {
def onRenderingOptionsChanged(ro, type)
cns = ro.class
suffix = case type
when cns::ROPDrawHidden
'DrawHidden'
when cns::ROPSetDisplayColorByLayer
'DisplayColorByLayer'
when cns::ROPSetDisplaySketchAxes
'DisplaySketchAxes'
when cns::ROPSetHideConstructionGeometry
'HideConstructionGeometry'
when cns::ROPSetModelTransparency
'ModelTransparency'
when cns::ROPSetRenderMode
'RenderMode'
when cns::ROPSetSectionDisplayMode
'SectionDisplayMode'
when cns::ROPSetTexture
'Texture'
else "Not caught by case statement"
end
puts suffix
end
}
# attach it to the Rendering_options of the model
Sketchup.active_model..add_observer(@obs_ro2)
The following table lists RenderingOptions keys which fire callbacks in a RenderingOptionsObserver callback. As mentioned, some keys generate more than one callback, and, any row with '** Missing, type =' in the 'Observer constant (type)' column fired a callback, but there isn't a RenderingOptions constant with that value. It is sorted by RenderingOption value.class, RenderingOption key, and Constant name. Duplicate values are shown bolded. Note that since these seem to have a many-to-many relationship, the testing done may not show all combinations.
RenderingOptions key | RenderingOptions value.class | Observer constant (type) |
---|---|---|
DisplayColorByLayer | Boolean | ROPSetDisplayColorByLayer |
DisplayDims | Boolean | ROPSetDisplayDims |
DisplayFog | Boolean | ROPSetDisplayFog |
DisplayInstanceAxes | Boolean | ROPSetDisplayInstanceAxes |
DisplaySketchAxes | Boolean | ROPSetDisplaySketchAxes |
DisplayText | Boolean | ROPSetDisplayText |
DisplayWatermarks | Boolean | ** Missing, type = 54 |
DrawDepthQue | Boolean | ROPSetDepthQueEdges |
DrawGround | Boolean | ROPSetDrawGround |
DrawHidden | Boolean | ROPDrawHidden |
DrawHorizon | Boolean | ROPSetDrawHorizon |
DrawLineEnds | Boolean | ROPSetLineEndEdges |
DrawProfilesOnly | Boolean | ROPSetProfilesOnlyEdges |
DrawSilhouettes | Boolean | ROPSetProfileEdges |
DrawUnderground | Boolean | ROPSetDrawUnderground |
ExtendLines | Boolean | ROPSetExtendLines |
FogUseBkColor | Boolean | ROPSetFogUseBkColor |
HideConstructionGeometry | Boolean | ROPSetHideConstructionGeometry |
InactiveHidden | Boolean | ROPEditComponent |
InstanceHidden | Boolean | ROPEditComponent |
JitterEdges | Boolean | ROPSetJitterEdges |
MaterialTransparency | Boolean | ROPSetMaterialTransparency |
ModelTransparency | Boolean | ROPSetModelTransparency |
Texture | Boolean | ROPSetTexture |
DepthQueWidth | Fixnum | ROPSetDepthQueWidth |
EdgeColorMode | Fixnum | ROPSetEdgeColorMode |
EdgeDisplayMode | Fixnum | ROPSetEdgeDisplayMode |
EdgeType | Fixnum | ROPSetEdgeType |
FaceColorMode | Fixnum | ROPSetFaceColorMode |
GroundTransparency | Fixnum | ROPSetGroundTransparency |
LineEndWidth | Fixnum | ROPSetLineEndWidth |
LineExtension | Fixnum | ROPSetLineExtension |
RenderMode | Fixnum | ROPSetEdgeDisplayMode |
RenderMode | Fixnum | ROPSetRenderMode |
SectionCutWidth | Fixnum | ROPSetSectionCutWidth |
SilhouetteWidth | Fixnum | ROPSetProfileWidth |
TransparencySort | Fixnum | ROPTransparencySortMethod |
FogEndDist | Float | ROPSetFogDist |
FogStartDist | Float | ROPSetFogDist |
InactiveFade | Float | ROPEditComponent |
InstanceFade | Float | ROPEditComponent |
BackgroundColor | Sketchup::Color | ROPSetBackgroundColor |
ConstructionColor | Sketchup::Color | ROPSetConstructionColor |
FaceBackColor | Sketchup::Color | ROPSetFaceColor |
FaceFrontColor | Sketchup::Color | ROPSetFaceColor |
FogColor | Sketchup::Color | ROPSetFogColor |
ForegroundColor | Sketchup::Color | ROPSetForegroundColor |
GroundColor | Sketchup::Color | ROPSetGroundColor |
HighlightColor | Sketchup::Color | ROPSetHighlightColor |
LockedColor | Sketchup::Color | ROPSetLockedColor |
SectionActiveColor | Sketchup::Color | ROPSetSectionActiveColor |
SectionDefaultCutColor | Sketchup::Color | ROPSetSectionDefaultCutColor |
SectionInactiveColor | Sketchup::Color | ROPSetSectionInactiveColor |
SkyColor | Sketchup::Color | ROPSetSkyColor |
The following table lists RenderingOptions keys that do not fire the onRenderingOptionsChanged callback.
R Opts key | R Opts value.class |
---|---|
BandColor | Sketchup::Color |
HorizonColor | Sketchup::Color |
ShowViewName | Boolean |
The following RenderingOptions constants are not fired by any keys in RenderingOptions. They may be returned for UI changes that do not have API control.
Observer constant (type) | value |
---|---|
ROPAssign | 0 |
ROPSetExtendEdges | 7 |
ROPSetFogHint | 24 |
ROPSetSectionDisplayMode | 25 |
ROPSetTransparencyObsolete | 2 |
Global Object Constants
Geometry Class constants
These constants can be used anywhere instances of their respective classes are used.
constant | value | class |
---|---|---|
IDENTITY | # | Geom::Transformation |
ORIGIN | (0", 0", 0") | Geom::Point3d |
X_AXIS | (1.0, 0.0, 0.0) | Geom::Vector3d |
Y_AXIS | (0.0, 1.0, 0.0) | Geom::Vector3d |
Z_AXIS | (0.0, 0.0, 1.0) | Geom::Vector3d |
Other object constants
The only other object constant defined is Sketchup::Console.
SKETCHUP_CONSOLE.write("this way also")
constant | value |
---|---|
SKETCHUP_CONSOLE | # |
Global Numeric Constants
Sketchup.send_action
Sketchup.send_action(action)
See Sketchup.send_action. This method allows for either a string or a number for its parameter. Numbers are officially 'unsupported', and only available under Windows.
The following code produces the same result.
bln = Sketchup.send_action("selectArcTool:") # use a String
bln = Sketchup.send_action(CMD_ARC) # use a Constant
bln = Sketchup.send_action(21065) # use a Fixnum
bln = Sketchup.send_action(action) # action can be either
Some strings are not listed on SketchUp.com. If one needs an unlisted menu item
string, one can assign a keyboard shortcut, then either view them with
Sketchup.get_shortcuts.sort.join("\n")
or by exporting the 'Preferences' from
the UI and viewing the .dat file in a text editor. If a string ending in ':' is
shown...
The following table shows strings (taken from SketchUp.com Nov-15), and their constant equivalents. Matches were done via RegEx and several lines of case statement.
action String | action Constant | Fixnum |
---|---|---|
copy: | CMD_COPY | 57634 |
cut: | CMD_CUT | 57635 |
editHide: | ||
editRedo: | CMD_REDO | 57644 |
editUndo: | CMD_UNDO | 57643 |
editUnhide: | ||
fixNonPlanarFaces: | ||
getPhotoTexture: | ||
openDocument: | CMD_OPEN | 57601 |
pageAdd: | CMD_PAGE_NEW | 21067 |
pageDelete: | CMD_PAGE_DELETE | 21078 |
pageNext: | CMD_PAGE_NEXT | 10535 |
pagePrevious: | CMD_PAGE_PREVIOUS | 10536 |
pageUpdate: | CMD_PAGE_UPDATE | 21068 |
paste: | CMD_PASTE | 57637 |
printDocument: | CMD_PRINT | 57607 |
renderHiddenLine: | CMD_HIDDENLINE | 10511 |
renderMonochrome: | ||
renderShaded: | CMD_SHADED | 10512 |
renderTextures: | CMD_TEXTURED | 10539 |
renderWireframe: | CMD_WIREFRAME | 10510 |
selectArc3PointPieTool: | ||
selectArc3PointTool: | ||
selectArcTool: | CMD_ARC | 21065 |
selectAxisTool: | ||
selectCircleTool: | CMD_CIRCLE | 21096 |
selectDimensionTool: | CMD_DIMENSION | 21410 |
selectDollyTool: | CMD_DOLLY | 10523 |
selectEraseTool: | CMD_ERASE | 21019 |
selectExtrudeTool: | CMD_EXTRUDE | 21525 |
selectFieldOfViewTool: | CMD_DISPLAY_FOV | 21494 |
selectFreehandTool: | CMD_FREEHAND | 21031 |
selectImageIglooTool: | ||
selectLineTool: | CMD_LINE | 21020 |
selectMeasureTool: | CMD_MEASURE | 21024 |
selectMoveTool: | CMD_MOVE | 21048 |
selectNorthTool: | ||
selectOffsetTool: | CMD_OFFSET | 21100 |
selectOrbitTool: | CMD_ORBIT | 10508 |
selectPaintTool: | CMD_PAINT | 21074 |
selectPolygonTool: | CMD_POLYGON | 21095 |
selectPositionCameraTool: | CMD_POSITION_CAMERA | 21169 |
selectProtractorTool: | CMD_PROTRACTOR | 21057 |
selectPushPullTool: | CMD_PUSHPULL | 21041 |
selectRectangle3PointTool: | ||
selectRectangleTool: | CMD_RECTANGLE | 21094 |
selectRotateTool: | CMD_ROTATE | 21129 |
selectScaleTool: | CMD_SCALE | 21236 |
selectSectionPlaneTool: | CMD_SECTION | 21337 |
selectSelectionTool: | CMD_SELECT | 21022 |
selectTextTool: | CMD_TEXT | 21405 |
selectTurnTool: | CMD_PAN | 10525 |
selectWalkTool: | CMD_WALK | 10520 |
selectZoomTool: | CMD_ZOOM | 10509 |
selectZoomWindowTool: | CMD_ZOOM_WINDOW | 10526 |
showRubyPanel: | CMD_RUBY_CONSOLE | 21478 |
viewBack: | CMD_VIEW_BACK | 10505 |
viewBottom: | CMD_VIEW_BOTTOM | 10506 |
viewFront: | CMD_VIEW_FRONT | 10502 |
viewIso: | CMD_VIEW_ISO | 10507 |
viewLeft: | CMD_VIEW_LEFT | 10504 |
viewPerspective: | CMD_VIEW_PERSPECTIVE | 10519 |
viewRight: | CMD_VIEW_RIGHT | 10503 |
viewShowAxes: | CMD_SKETCHAXES | 10522 |
viewShowGuides: | CMD_SHOWGUIDES | 21980 |
viewShowHidden: | CMD_SHOWHIDDEN | 21154 |
viewTop: | CMD_VIEW_TOP | 10501 |
viewUndo: | ||
viewZoomExtents: | CMD_ZOOM_EXTENTS | 10527 |
viewZoomToSelection: | CMD_SELECTION_ZOOM_EXT | 21469 |
The following constants do not have string equivalents.
action constant | value | action constant | value | |
---|---|---|---|---|
CMD_CAMERA_UNDO | 10529 | CMD_NEW | 57600 | |
CMD_DELETE | 21021 | CMD_SAVE | 57603 | |
CMD_DRAWCUTS | 21348 | CMD_SKETCHCS | 21126 | |
CMD_DRAWOUTLINES | 21347 | CMD_TRANSPARENT | 10513 | |
CMD_MAKE_COMPONENT | 21083 |
Sketchup.set_status_text
See Sketchup.set_status_text. Text can be placed in three different locations. The constants are used as the position parameter and define the location.
result = Sketchup.set_status_text("This is a Test", SB_VCB_VALUE)
result = Sketchup.set_status_text(status, position)
position | value |
---|---|
SB_PROMPT | 0 |
SB_VCB_LABEL | 1 |
SB_VCB_VALUE | 2 |
Command #set_validation_proc
See Command#set_validation_proc. The value returned by the block determines the display state of a command, which can be a menu item, a toolbar button, or both.
= UI::Toolbar.new "YourToolbar"
= UI.("Draw").("Yours")
cmd = UI::Command.new("YourCmd") { some method() }
cmd. = "My Command"
cmd.small_icon = "YourCmdSmall.png"
cmd.large_icon = "YourCmdLarge.png"
cmd.set_validation_proc {
# process
return cmd_status
}
.add_item cmd
.add_item cmd
cmd_status | value |
---|---|
MF_CHECKED | 8 |
MF_DISABLED | 2 |
MF_ENABLED | 0 |
MF_GRAYED | 1 |
MF_UNCHECKED | 0 |
Definition #behavior #snapto
See Behavior#snapto. To quote SketchUp.com help, 'The Behavior class is used to control the "behavior" of components'.
model = Sketchup.active_model
definition = model.definitions[0]
behavior = definition.behavior
snap_to = behavior.snapto
behavior.snapto = snap_to
snap_to | value |
---|---|
SnapTo_Arbitrary | 0 |
SnapTo_Horizontal | 1 |
SnapTo_Sloped | 3 |
SnapTo_Vertical | 2 |
Layer #page_behavior #page_behavior=
See Layer#page_behavior. This attribute is a numeric, with somewhat confusing documentation. From the docs, 'The behavior is composed of a combination of these flags'. So default visiblity is bit 0 ('HIDDEN' is set), why does 'NEW_PAGES' have 'VISIBLE' setting bit 4 and 'HIDDEN' setting bit 5? Seems that they should be mutually exclusive.
layers = Sketchup.active_model.layers
layer.page_behavior = page_behavior
page_behavior = layers[0].page_behavior
puts page_behavior[0] # this is default visiblity
puts page_behavior[4] # this new pages visible?
puts page_behavior[5] # this new pages hidden?
constant | value |
---|---|
LAYER_USES_DEFAULT_VISIBILITY_ON_NEW_PAGES | 0 |
LAYER_VISIBLE_BY_DEFAULT | 0 |
LAYER_HIDDEN_BY_DEFAULT | 1 |
LAYER_IS_VISIBLE_ON_NEW_PAGES | 16 |
LAYER_IS_HIDDEN_ON_NEW_PAGES | 32 |
Page #update, Pages #add
See Page#update and Pages#add. These bit constants are used for the flag parameter.
am = Sketchup.active_model
status = am.pages.add(name, flags = nil, index = nil)
am.pages['yourPage'].update(flags = nil)
flag parameter | value | flag parameter | value | |
---|---|---|---|---|
PAGE_NO_CAMERA | 4094 | PAGE_USE_RENDERING_OPTIONS | 2 | |
PAGE_USE_ALL | 4095 | PAGE_USE_SECTION_PLANES | 64 | |
PAGE_USE_CAMERA | 1 | PAGE_USE_SHADOWINFO | 4 | |
PAGE_USE_HIDDEN | 16 | PAGE_USE_SKETCHCS | 8 | |
PAGE_USE_LAYER_VISIBILITY | 32 |
Text #leader_type #leader_type=
See Text#leader_type
leader = text.leader_type
text.leader_type = leader
leader | value |
---|---|
ALeaderModel | 2 |
ALeaderNone | 0 |
ALeaderView | 1 |
TextureWriter #write
tw = Sketchup.create_texture_writer
status = tw.write(entity, side, filename)
status return | value |
---|---|
FILE_WRITE_FAILED_INVALID_TYPE | 1 |
FILE_WRITE_FAILED_UNKNOWN | 2 |
FILE_WRITE_OK | 0 |
Tool #onKeyDown, Tool #onKeyUp
See Tool#onKeyDown. The constants are the key parameter, VK_PRIOR is 'Page Up', VK_NEXT is 'Page Down'.
- A-Z keys return 65-90
- qwerty number keys are 48-57
- keypad number keys are 96-105
I could not get any information from the flags parameter. I would suggest using keyUp and KeyDown to keep track of modifier key state. The next section has code that attaches to mouse and keyboard events.
def onKeyDown(key, repeat, flags, view)
key cb parameter | value | key cb parameter | value |
|
---|---|---|---|---|
VK_ALT | 18 | VK_LEFT | 37 | |
VK_COMMAND | 18 | VK_MENU | 18 | |
VK_CONTROL | 17 | VK_NEXT | 34 | |
VK_DELETE | 46 | VK_PRIOR | 33 | |
VK_DOWN | 40 | VK_RIGHT | 39 | |
VK_END | 35 | VK_SHIFT | 16 | |
VK_HOME | 36 | VK_SPACE | 32 | |
VK_INSERT | 45 | VK_UP | 38 |
Tool #onMouse
See Tool #onLButtonDoubleClick. A total of nine mouse button events exist: up, down, and double click, for left, middle, and right buttons. Under Windows:
- A user can click more than one button at once.
- The 'flags' bits for which buttons are pressed are not set on the 'Up' events for a single button press.
- On a double button press and release, a single down event will often fire, the the double. On release, first the wrong button will fire an event, the a 'blank' up event.
- 'Down' and 'Up' events fire first, then the 'DoubleClick' event fires.
All methods have the following for parameters -
def onLButtonDown(flags, x, y, view)
# your code
end
Below is code that shows use of the constants, also some "doesn't quite work" key code. Located in the template_code.rb file. Load, then SUMD_TC.new.tool_1.
@@mse = Proc.new { |up_down_dbl, flags, x, y, view|
= ''
key_mod = ''
if (MK_LBUTTON & flags != 0) then << ', Left' end
if (MK_MBUTTON & flags != 0) then << ', Middle' end
if (MK_RBUTTON & flags != 0) then << ', Right' end
if (MK_SHIFT & flags != 0) then key_mod << ', Shift' end
if (MK_CONTROL & flags != 0) then key_mod << ', Ctrl' end
if (MK_ALT & flags != 0) then key_mod << ', Alt' end
s1 = up_down_dbl.ljust(7)
s2 = .sub(/^, /, '').ljust(20)
s3 = key_mod.sub(/^, /, '')
puts "Mouse Button #{s1} button = #{s2} keys = #{s3}"
}
@tool = Object.new
@tool.instance_eval {
def onLButtonDown(*a) ; @@mse.call('Down' , *a) ; end
def onMButtonDown(*a) ; @@mse.call('Down' , *a) ; end
def onRButtonDown(*a) ; @@mse.call('Down' , *a) ; end
def onLButtonUp(*a) ; @@mse.call('Up' , *a) ; end
def onMButtonUp(*a) ; @@mse.call('Up' , *a) ; end
def onRButtonUp(*a) ; @@mse.call('Up' , *a) ; end
def onLButtonDoubleClick(*a) ; @@mse.call('DblClk', *a) ; end
def onMButtonDoubleClick(*a) ; @@mse.call('DblClk', *a) ; end
def onRButtonDoubleClick(*a) ; @@mse.call('DblClk', *a) ; end
def onKeyDown(key, repeat, flags, view)
# Some binary fun for testing
t = flags.to_s(2).rjust(16)
bin = "#{ t[-16,4]} #{ t[-12,4]} " \
"#{ t[ -8,4]} #{ t[ -4,4]}".rjust(19)
puts "#{key.to_s.ljust(4)}\t#{flags.to_s.ljust(5)}\t#{bin}"
k = key.to_s.rjust(3)
alt = (ALT_MODIFIER_MASK & key != 0).to_s.ljust(5)
cons = (CONSTRAIN_MODIFIER_MASK & key != 0).to_s.ljust(5)
copy = (COPY_MODIFIER_MASK & key != 0).to_s.ljust(5)
puts "key = #{k} alt = #{alt} cons = #{cons} copy = #{copy}"
end
}
Sketchup.active_model.select_tool(@tool)
flags cb parameter | value | flags cb parameter | value |
|
---|---|---|---|---|
MK_ALT | 32 | MK_MBUTTON | 16 | |
MK_COMMAND | 0 | MK_RBUTTON | 2 | |
MK_CONTROL | 8 | MK_SHIFT | 4 | |
MK_LBUTTON | 1 |
Toolbar #get_last_state
state = .get_last_state
state return | value |
---|---|
TB_HIDDEN | 0 |
TB_NEVER_SHOWN | -1 |
TB_VISIBLE | 1 |
UI.messagebox
See UI.messagebox. MB_MULTILINE
shows a dialog with a scrollable text area
and an 'Okay' button.
status = UI.(, type)
status return | value | type parameter | value | |
---|---|---|---|---|
IDABORT | 3 | MB_ABORTRETRYIGNORE | 2 | |
IDCANCEL | 2 | MB_MULTILINE | 16 | |
IDIGNORE | 5 | MB_OK | 0 | |
IDNO | 7 | MB_OKCANCEL | 1 | |
IDOK | 1 | MB_RETRYCANCEL | 5 | |
IDRETRY | 4 | MB_YESNO | 4 | |
IDYES | 6 | MB_YESNOCANCEL | 3 |
View #draw
See View#draw
view = Sketchup.active_model.active_view
view.draw(mode, pts)
mode parameter | value | mode parameter | value | |
---|---|---|---|---|
GL_LINES | 1 | GL_QUADS | 7 | |
GL_LINE_LOOP | 2 | GL_QUAD_STRIP | 8 | |
GL_LINE_STRIP | 3 | GL_TRIANGLES | 4 | |
GL_POINTS | 0 | GL_TRIANGLE_FAN | 6 | |
GL_POLYGON | 9 | GL_TRIANGLE_STRIP | 5 |
View #draw_text
See View#draw_text. These constants are used in SketchUp 2016+ and control the text alignment.
:align value | value |
---|---|
TextAlignCenter | 1 |
TextAlignLeft | 0 |
TextAlignRight | 2 |
RUBY_ Constants, SketchUp Platform Constants
The following are RUBY_ and SketchUp constants which vary from version to version.
constant | value | class |
---|---|---|
PLATFORM | i386-mswin32 | String |
RELEASE_DATE | 2008-08-11 | String |
RUBY_PATCHLEVEL | 287 | Fixnum |
RUBY_PLATFORM | i386-mswin32 | String |
RUBY_RELEASE_DATE | 2008-08-11 | String |
RUBY_VERSION | 1.8.6 | String |
VERSION | 1.8.6 | String |
Depreciated Constants
I believe the following are depreciated. VK_ constants should be used in their place. I tried the mask constants on both the key and flags parameters, and nothing seemed to work.
constant | value |
---|---|
ALT_MODIFIER_KEY | 18 |
ALT_MODIFIER_MASK | 32 |
CONSTRAIN_MODIFIER_KEY | 16 |
CONSTRAIN_MODIFIER_MASK | 4 |
COPY_MODIFIER_KEY | 17 |
COPY_MODIFIER_MASK | 8 |
The following have been replaced by namespaced constants.
constant | value |
---|---|
DimensionArrowClosed | 3 |
DimensionArrowDot | 2 |
DimensionArrowNone | 0 |
DimensionArrowOpen | 4 |
DimensionArrowSlash | 1 |
Yet to be added to documentation or unknown
constant | value |
---|---|
Sketchup::Pages::ImageEmbedded | 0 |
Sketchup::Pages::ImageEmbeddedAndLinked | 1 |
Sketchup::Pages::ImageLinked | 2 |
Sketchup::Pages::UnitsNormalizedX | 2 |
Sketchup::Pages::UnitsNormalizedY | 1 |
Sketchup::Pages::UnitsPixels | 0 |