Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <head>
	<title>Hello Viewer with Codepen</title>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link rel="icon" href="data:,">
	<script src="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/viewer3D.min.js"></script>
	<link href="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/style.min.css" rel="stylesheet">
</head>

<body style="margin:0; overflow-y: hidden;">
	<div id="panel">
		<select id="folderList" onChange="comboBox.onChanged(this.selectedIndex)"></select>
		<a href="https://forge.autodesk.com/blog/fast-debugging-codepen-viewer-and-bim-360-acc-docs" target="_blank"> 
		&#8594; BLOG POST</a>&#9786;
	</div>
	
	<div id="Viewer"></div>
</body>
              
            
!

CSS

              
                #panel {
	position: fixed;
	z-index: 2;
	margin: 10px;
	font-family:arial;
	font-size:1.5em;
}

              
            
!

JS

              
                // add your accessToken and hub to the URL, ie
// https://codepen.io/wallabyway/pen/yLEPQap?hub=<INSERT HUB>&accessToken=<INSERT TOKEN>
// See Blog for details: https://forge.autodesk.com/author/michael-beale

const AV = Autodesk.Viewing;
const div = document.getElementById("Viewer");

///////////////////////////////////////////////////////////////////
// your extension code goes here.... 
class MyExtension extends AV.Extension {
	unload() { return true }
	
	load() {
		this.viewer.addEventListener(AV.SELECTION_CHANGED_EVENT, (e) => this.onSelect(e) );
		return true;
	}
	onSelect(e) {
		const RED_COLOR = new THREE.Vector4(0, 1, 0, 1);
		if (e.dbIdArray.length>0)
			this.viewer.setThemingColor(e.dbIdArray[0], RED_COLOR );
		
	}
}
AV.theExtensionManager.registerExtension("MyExtension", MyExtension);
///////////////////////////////////////////////////////////////////


function startViewer(urn) {
	AV.Initializer({ env: "AutodeskProduction" }, () => {
		const options = { extensions: ["MyExtension"] };
		const viewer = new AV.Private.GuiViewer3D(div, options);
		viewer.start();
		viewer.setTheme("light-theme");
		AV.Document.load(`urn:${urn}`, (doc) => {
			var viewables = doc.getRoot().getDefaultGeometry();
			viewer.loadDocumentNode(doc, viewables);
		});
	});
}


///////////////////////////////////////////////////////////////////
/// BIM 360 / ACC combo box

class comboBox {
	static onChanged(selectedIndex) {
		const URN = window.btoa(this.items[selectedIndex].id).replace(/=/g, "");
		startViewer(URN);
	}

	static async load(div) {
		const { project_id, folder_id, token } = this.parseURL(window.location.search);
		this.items = await this.fetchFolderContents(project_id, folder_id, token);
		this.items.map((i) => {
			div.appendChild(new Option(i.attributes.displayName)) });
		this.onChanged(0);
	}

	static async fetchFolderContents(project_id, folder_id, token) {
		const url = `https://developer.api.autodesk.com/data/v1/projects/${project_id}/folders/${folder_id}/contents`;
		const json = await ( await fetch(url, { headers: { Authorization: `Bearer ${token}` } }) ).json();
		return json.included;
	}

	static parseURL(URL) {
		const params = new URLSearchParams(URL);
		let hub = params.get("hub");
		const isACC = (hub.indexOf('acc')>0);
		const hubACC = hub.slice(36).split("?");
		const hubBIM = hub.slice(31).split("/");
		return {
			project_id: (isACC) ? `b.${hubACC[0].split('/')[1]}` : `b.${hubBIM[1]}`,
			folder_id: (isACC) ? hubACC[1].split('=')[1] : hubBIM[3],
			token: params.get("accessToken")
		};
	}
}
comboBox.load(document.getElementById("folderList"));


              
            
!
999px

Console